Getting specific value from JSON using javascript

前端 未结 2 1364
孤城傲影
孤城傲影 2021-01-14 13:29

I am using ajax to get a small set of data back from the server which returns JSON data with the following format:

{
    \"data\": [
        {
            \"         


        
2条回答
  •  无人及你
    2021-01-14 14:14

    If you parse it into a javascript object using something like jQuery's json parse method, you could just reference the various items in the array like a normal javascript array.

    Do it like this:

    var dataArray = $.parseJSON(myJson).data;
    
    var theFirstData = dataArray[0]; //get the data with id "1"
    

    Alternately, if you don't want to use jQuery, you can use JSON.parse(jsonToParse). Here're the docs for that method.

提交回复
热议问题