0

I have a string that is json like this:

{
"2045532196113651": [{
    "height": 42,
    "width": 75,
    "source": "https://url1"
}, {
    "height": 42,
    "width": 75,
    "source": "https://url2"
}],
"2045532296113641": [{
    "height": 50,
    "width": 75,
    "source": "https://url3"
}, {
    "height": 50,
    "width": 75,
    "source": "https://url4"
}]

}

The string has the variable name jsondata.

I want to get the numbers of the indexes in the json object (2045532196113651 and 2045532296113641) in this example. Also I want to get the 4 urls (url1, url2, url3, and url4).

How do I do that? I can use jquery.

1 Answer 1

2

First you parse the string so that you get an object, then you can loop it:

 var obj = $.parseJSON(jsondata);
 $.each(obj, function(key, value) {
   // key is the name of the item, e.g. "2045532196113651"
   // value is an array:
   $.each(value, function(idx, item) {
     // item.source contains the URL
   });
 });
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.