Reading a json encoded array in javascript

后端 未结 1 1289
梦谈多话
梦谈多话 2021-01-28 03:21

This php function returns a json encoded object to a javascript through ajax. I create a variable with this json object with stringify.

var event_id = JSON.strin         


        
1条回答
  •  遥遥无期
    2021-01-28 03:54

    Don't stringify it. It's already a valid JavaScript object, so just access it directly with:

    rdata.event_id[0]["0"];
    // e20111129215359
    
    // Or read them in a loop
    for (var i=0; i

    The value rdata.event_id is an array [] containing a bunch of object literals {} each having just one property "0". Since the property is a number instead of a string, you need to use the ["0"] syntax to access it, rather than the normal object dot operator.

    0 讨论(0)
提交回复
热议问题