[Solved] Parse JSON with custom structure in jquery [closed]


JSON data (for example, that returned from an AJAX call) is automatically “parsed” into a structure which is connected to a variable. Or, you can take a string and turn it into a structure using what Adrian showed.

Now, there is one thing about your structure that is problematic: “3” is, as far as I know, not an OK name within an associative array. Change that to “list” or something that meets the requirements of keys like so:

var projects = {"list":[
 {"project_id":27,"name":"Name1"},
 {"project_id":28,"name":"Name2"},
 {"project_id":29,"name":"Name3"},
 {"project_id":32,"name":"Name4"}
]};

Then you could access the elements like so.

console.log(projects.list);
console.log(projects.list[0].project_id, projects.list[0].name);

2

solved Parse JSON with custom structure in jquery [closed]