开发者

Not able to access Data inside Javascript Array

开发者 https://www.devze.com 2023-02-26 04:26 出处:网络
HI , var jsonObj = [] ; for (var i = 0; i < 开发者_C百科data.jobs.length; i++) { jsonObj.push({id: data.jobs[i].Dater, optionValue: data.jobs[i].INCPU});

HI ,

 var jsonObj = [] ;

for (var i = 0; i < 开发者_C百科data.jobs.length; i++) {

            jsonObj.push({id: data.jobs[i].Dater, optionValue: data.jobs[i].INCPU});
        }

alert(jsonObj);

I am getting as result as

[object Object],[object Object],[object Object]


That is because you are alerting an array. Trying alerting an individual index of that array.

alert(jsonObj[0])


If you want to produce a JSON serialisation, use a JSON parser library like json2.js.

The serialised form will also produce the expected result when you pass it to alert().


I believe you're trying to achieve this:

var obj = [];

// populate obj in a loop

var jsonStr = JSON.stringify(obj);

alert(jsonStr);

Live demo: http://jsfiddle.net/simevidas/Smd2P/1/

0

精彩评论

暂无评论...
验证码 换一张
取 消