如何使用JS解析json数据和字符串

$.ajax({
    url: "/recommend",
    type: "post",
    dataType: "json",
    // contentType: 'text/json,charset=utf-8',
    data: {
        "housetype": document.getElementById("housetype").innerHTML,  // 房主申请数
        "zone": document.getElementById("zone").innerHTML,  // 待审核房源数

    },
    success:function (jsonString) {
   alert(JSON.stringify(jsonString.data[0].housetype))

    }

})

返回的字符串

{"code":100,"msg":"处理成功!","data":[{"hid":"20181127211233","housetype":"二手房","title":"厦大白城 3室1厅","univalence":"5000","acreage":"90","direction":"东","average":"0.00","year":"12个月","type":"出租","height":"3/9","decoration":"精简装修","other":"面朝大海","city":"厦门市","zone":"思明区","address":"厦大白城","phone":"18359222476","status":0,"photo":"myhouseImage/housephoto/18359222476/20191198524/drawing.jpg","time":"20191198524"}]}
 

需要得到data数组

JSON.stringify(jsonString.data)

得到第一个数组

JSON.stringify(jsonString.data[0]

得到第一个数组的值

JSON.stringify(jsonString.data[0].housetype

你可能感兴趣的:(JSON)