0

My json data is as follows:

"query": {
  "count": 1,
   "url": [
    {
     "execution-start-time": "1"
    },
    {
     "execution-time": "745"
    }
   ],
   "service-time": "1481"
  },
      results": {
       "div": {
        "class": "makers",
        "ul": {
         "li": [
          {
           "a": {
            "href": "nokia_x2_dual_sim-6383.php",
            "img": {
             "src": "Nokia-X2-Dual-SIM.jpg"
            },
            "strong": {
             "br": null,
             "content": "Nokia\nX2 Dual SIM"
            }
           }
          },
          {
           "a": {
            "href": "nokia_xl-6148.php",
            "img": {
             "src": "nokia-xl.jpg",
            },
            "strong": {
             "br": null,
             "content": "Nokia\nXL"
            }
           }
          }
         ]

Now I want to extract the "content" part from this json data using jsonpath.I am using jsonpath-0.8.0.js for this purpose.

I have tried to parse the json data in the following way:

function ParseData(data) {
  var result = jsonPath(data, "$.query.results[*].ul.li[*].strong.content");
  $('#carousel').empty();
  var html = "";
  for (i = 0; i < result.length; i++) {
   // do something
   }

and I was expecting to get Nokia\nX2 Dual SIM and Nokia\nXL as output but this code of mine does not return anything.I cannot understand the problem.

How do I extract the content data from this json? please help.

1 Answer 1

2

Friends, I finally got the answer to my problem.I used the following code to extract content from the above given json data.

var result = jsonPath(data, "$.query.results[*].ul.li[*].a.strong.content");

Now I am getting the output data as expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.