Loading Non-Linear JSON

Last November, there was a bug report in JSON Table Editor‘s support page. The person note that the table editor unable to load non-linear JSON. If he loaded the following JSON, the table is only showing two columns:

[{ "name" : "gggg", "desc" : "gggg"},
 { "text" : "gggg" },
 { "text" :"gggg" },
 { "text" : "gggg" }]

So today I finally have the time to look at this problem. After a quick look, I realized that it’s a simple problem. Previously, the ExtJS Store is initialized with the first object in the JSON array. Now, we must iterate all items inside the array and combining all of their attributes.

We do it as follows:

	// ...... CODE SNIP ......
	//obj is the JSON array
	var initObj = obj[0];
	//copy all properties' name into initObj
	Ext.each(obj, function(item){
		for (var key in item)
			if (initObj[key] == undefined)
				if (typeof(item[key]) == "number")
					initObj[key] = 0;
					initObj[key] = "";
	//initialize the ExtJS Store with initObj
	// ...... CODE SNIP ......

And it works:


Happy holidays all!


GD Star Rating
Loading Non-Linear JSON, 4.0 out of 5 based on 1 rating
Worth sharing ?

Incoming Search Term

Advertise Here

1 Trackback



No Comment

Add Your Comment