I am needing to grab some JSON from a site and parse it. The problem is that the objects are named “-1” “-2” and so forth.
When I try to parse it, Firebug comes back with, “TypeError: obj is undefined
length = obj.length”
Chrome comes back with a similar message, “Uncaught TypeError: Cannot read property ‘length’ of undefined”
For reference, here’s a snipet of the JSON:
{
"-1": {
"number": 47,
"properties": [
[
And here’s the code I’m trying to use.
$.getJSON("http://www.website.com/builds?select=-1&select=-10",function(data){
$.each(data.-1, function(info,value){
If I download the JSON, save it locally and rename “-1” to “one”, rename “-2” to “two”, then it works fine. E.G. the JSON becomes:
{
"one": {
"number": 47,
"properties": [
[
And my code becomes
$.getJSON("C:\json.json",function(data){
$.each(data.one, function(info,value){
This works fine, but it adds another complicated step.
Is there a way to parse on the original JSON (as it is generated automatically from a server, and changes often), or am I stuck with trying to figure out how to save it locally and change the object names before parsing?
data.-1must be referenced as a string using bracket notation.data["-1"]