Here's a snippet of my code. Note $inventors_obj holds the data.{ "items" : [ { "name" : "Theodor Nelson", "id": "_333301" }, { "name": "Morton Heilig", "id": "_13204" } ] }
But $inventors_obj->{"items} appears to be returning a single object, rather than an array. How can iterate through it, change things, and print it back to JSON?$inventors_obj = jsonToObj($inventors_json[0]); #I want to iterate through my list of inventors @inventors_array = $inventors_obj->{"items"};
However, if I convert the object to an array of hashes (how do I do this, "unblessing"?), can I get it back out in JSON? Is there a way I can manipulate it while keeping it as an object?#print name doesn't work, because the entire object is #stored at $inv +entors_array[0]. print $inventors_array[0]->{"name"} #So this doesn't work: print $inventors_array[1]->{"name"} #I am not sure if this is possible to even alter data #generically wit +h objects, even though I thought they were #really just arrays of hashes: $inventors_array[1]->{"name"} = "New Name"; #But I can do with an array of hashes... $inventors_array[1]{"name"} = "New Name";
In reply to JSON and Perl Objects - How to access data? by harryhalpin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |