我從ajax調用得到下面的回報,但無法遍歷它請請幫助。Json遍歷問題,無法遍歷值
{ "1": { "tel1": null, "status": "1", "fax": "", "tel2": null, "name": "sh_sup1", "country": "Anguilla", "creation_time": "2010-06-02 14:09:40", "created_by": "0", "Id": "85", "fk_location_id": "3893", "address": "Noida", "email": "[email protected]", "website_url": "http://www.noida.in", "srk_main_id": "0" }, "0": { "tel1": "Ahemdabad", "status": "1", "fax": "", "tel2": "Gujrat", "name": "Bharat Petro", "country": "India", "creation_time": "2010-05-31 15:36:53", "created_by": "0", "Id": "82", "fk_location_id": "3874", "address": "THIS is test address", "email": "[email protected]", "website_url": "http://www.bp.com", "srk_main_id": "0" }, "count": 2 }
我重新格式化它。您還需要告訴我們您使用的是哪種語言,需要什麼樣的遍歷以及您嘗試過的內容。另外,這是奇怪的JSON。所有的數字都是字符串,它使用帶有「0」和「1」鍵的對象而不是更自然的數組。 – 2010-06-03 07:03:32
我使用php,我使用json_encode 從服務器編碼php數組,並將其返回給客戶端,現在我想遍歷這個json數據什麼即時通訊使用javascript only.Count可以刪除它只是添加數數元素的形成。請建議 – Jos 2010-06-03 07:08:44
@Jos:呃...你用'json_encode'對它進行編碼......那麼爲什麼不用'json_decode'來解碼它呢?然後訪問你想要的任何變量,就像你通常使用PHP關聯數組一樣.. – mpen 2010-06-03 07:13:53