2016-10-05 128 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