jQuery显示不正确的JSON结果

时间:2016-10-05 13:06:11

标签: jquery json

jQuery代码:

for (var i = 0; i < data.length; i++) {
    console.log(data);
    list += '<div class="col-sm-12"><div class="product-view row" style="border-bottom:1px solid #eee;margin-bottom:20px;padding:20px 0px 20px 0px;background:#f1f1f1"><div class="col-sm-3 col-md-3 col-lg-3"> <div class="large-image"> <img alt="#" src="' + base_url + '/uploads/' + data[i]['cate'][0]['Image'] + '"><div class="image-title"><span class="icon-thumbs-up" onclick="thumb(' + data[i]['UniqueID'] + ',this)" style="font-size:24px;"></span></div></div></div><div class="col-sm-6 col-md-6 col-lg-6"> <div class="product-label"><h4>' + data[i]['FullName'] + ', ' + data[i]['Area'] + '</h4><h5 style="font-size:14px;width: 100%;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;"><span class="icon-calendar"></span>  ' + data[i]['SaleDate'] + '</h5><div data-balloon-length="fit" data-balloon="' + data[i]['Address1'] + '" data-balloon-pos="up" ><h5 style="font-size:14px;width: 100%;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;"><span class="icon-home"></span>  ' + data[i]['Address1'] + '</h5></div><div data-balloon-length="fit" data-balloon="'+data[i]['description']+'" data-balloon-pos="up" ><h5 style="font-size:14px;width: 100%;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;"><span class="icon-file"></span>  ' + data[i]['description'] + '</h5></div></div></div><div class="col-sm-3 col-md-3 col-lg-3"><div class="product-label"><h4>CATEGORY</h4>';
    var times = '';
    for (r = 0; r < data[i]['StartTime'].length; r++) {
        console.log(data[i]['StartTime'][r]);
    }
    cates = '';
    for (var j = 0; j < data[i]['cate'].length; j++) {
        cates += '<h5 style="font-size:14px">' + data[i]['cate'][j]['Product'] + '</h5>';
    };
    list += cates + '</div></div></div></div>';
};

JSON:

[{"ID":"27","FullName":"shah rushabh","UniqueID":"938218","MobileNumber":"9429058733","EmailAddress":"shahrushabh1996@gmail.com","Address1":"B\/1 Rajasthan Appartment, Kabirchowk, Sabarmati, Ahmedabad","Address2":"","Area":"Sabarmati","city":"Ahmedabad","State":"Gujarat","Postal":"380005","SaleDate":"2016-10-04","StartTime":"[\"9:00pm\"]","EndTime":"[\"10:00pm\"]","description":"hello mr rushbh shah","Status":"active","Thumb":"1","cate":[{"ID":"63","UniqueID":"938218","Product":"electronics","Image":"938218\/logo.png"},{"ID":"64","UniqueID":"938218","Product":"decoratives \/ Interior","Image":"http:\/\/wallpapercraze.com\/images\/wallpapers\/nowallpaper-585747.j"},{"ID":"65","UniqueID":"938218","Product":"Furnitures","Image":"http:\/\/wallpapercraze.com\/images\/wallpapers\/nowallpaper-585747.j"}]}]

StartTime的结果:

[
"
9
:
0
0
p
m
"
]

StartTime是嵌套的JSON,它一个接一个地显示StartTime,我该如何解决它?

提前感谢。

1 个答案:

答案 0 :(得分:2)

因为你的JSON错了。你没有数组,你有一个字符串。

"StartTime":"[\"9:00pm\"]"

应该是

"StartTime": ["9:00pm"]