read JSON data from Javascript

This question already has an answer here:

  • Safely turning a JSON string into an object 22 answers

  • You have to parse the data into an object variable:

    var data = JSON.parse( datastring );
    

    After that, you can address certain properties directly (eg data.status).


    既然这是一个数组,你应该像访问它

    var data = JSON.parse(json_string);
    var status = data[2].status
    

    I suggest restructuring the response from the server if possible, since the response is not so well-formatted.

    Step 1 : Change the response as follows:

    {
     "value1":
    
           {"longitude":"103.8439764",
            "latitude":"1.0345","date":"Tue 04 Jun, 2013",
            "time":"12:27"},
    
     "value2":
           {"longitude":"104.8439764",
            "latitude":"1.235","date":"Mon 03 Jun, 2013",
            "time":"12:28"},
     "status":
            "his_loc"
    
    }
    

    Step 2 : Parse the response to a JSON object.

    var json = JSON.parse(responseString);
    

    And now you can access the status as follows:

    var status = json.status;
    

    That's it!

    链接地址: http://www.djcxy.com/p/31726.html

    上一篇: jQuery:从json响应获取订单ID

    下一篇: 从Javascript读取JSON数据