How to loop on a JSON object?

前端 未结 2 1197
花落未央
花落未央 2020-12-21 00:31

I have this JSON object:

{\"time\":\"123456789\", \"raw\":\"chat_history\", \"data\":{
\"msg\":[
 {\"time\":1111111111, \"user\":\"user1\", \"text\":\"text f         


        
相关标签:
2条回答
  • 2020-12-21 00:44
    for(var i = 0; i < data.msg.length; i++)
    {
        var row = data.msg[i];
        print(row.time + ' - ' + row.user + ' - ' + row.text);
    }
    
    0 讨论(0)
  • 2020-12-21 01:02
    var msg = yourJsonObject.data.msg;
    
    for (var i = 0, len = msg.length; i < len; i++) {
      // document.write only for example
      document.write(msg[i].time + ' - ' + msg[i].user + ' - ' + msg[i].text);
    }
    
    0 讨论(0)
提交回复
热议问题