How to access values in a multidimensional JSON array with jQuery

拟墨画扇 提交于 2019-12-01 11:47:01
swatkins

If the output of value.producer is an object, then you should be able to access the properties of that object. For example, value.producer.name should output 'asdfsadf'.

UPDATE

It looks as though your json data is not valid. (I'm assuming "producers" is a property of the data object and the value of that property is an array of all of the "producer" objects.)

I've created this fiddle ( http://jsfiddle.net/kAsPm/ ) and it works as expected. I just had to change the comma to a colon after "producers":

"producers":  // changed from "producers",
[
    {
        "producer":{
            "id":"1",
            ...

Open your firebug's console, paste the following and execute:

var json = '{' + 
'"peopleList":[' +
'{"id":1,"name":"marcelo","address":"rua meh","phone":"85 99999999"},'+
'{"id":2,"name":"marcelo2","address":"rua meh2","phone":"85 9999.9999"}]}';

var parsed = JSON.parse(json);

Now, as you will have two objects under the second level of your JSON, you need to specify the object and then you will see that it will allow you to select its properties:

parsed.peopleList[0].name

Before working with the dynamically generated JSON, get some dummy data for testing purposes (with the same structure, of course) and play with it before implementing the final code.

I used tempo.js rendering engine, it does multidimensional array rendering. here is the link http://tempojs.com/

download tempo.cs and follow the link .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!