Use a JSON array with objects with javascript

后端 未结 6 1578
执笔经年
执笔经年 2021-01-30 03:29

I have a function that will get a JSON array with objects. In the function I will be able to loop through the array, access a property and use that property. Like this:

6条回答
  •  迷失自我
    2021-01-30 03:43

    Your question feels a little incomplete, but I think what you're looking for is a way of making your JSON accessible to your code:

    if you have the JSON string as above then you'd just need to do this

    var jsonObj = eval('[{"id":28,"Title":"Sweden"}, {"id":56,"Title":"USA"}, {"id":89,"Title":"England"}]');
    

    then you can access these vars with something like jsonObj[0].id etc

    Let me know if that's not what you were getting at and I'll try to help.

    M

提交回复
热议问题