2016-10-05 169 views
0

jQuery代码:jQuery的显示不正确JSON结果

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":"[email protected]","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"}]}] 

开始时间的结果:

[ 
" 
9 
: 
0 
0 
p 
m 
" 
] 

开始时间是嵌套JSON它显示一个由开始时间的一个字符我该如何解决它?

在此先感谢。

+1

'StartTime'似乎是一个* *嵌套JSON阵列。您需要(奇怪的是)将其解析为JSON,或者在序列化数据的任何位置修复,以便不会对其进行双重序列化。 – meagar

回答

2

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

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

它应该是

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

'StartTime'=> json_encode($ newStartTime), 'EndTime'=> json_encode($ newEndtime), –

+1

为什么你json_encode呢?你不应该。 – epascarello

+0

@shahrushabh是的,不要这样做。没有理由独立JSON编码较大的JSON响应的子元素。 – meagar