2013-05-04 158 views
1

我有一個像這樣的Json字符串:[{"Row_id":"1","Name":"AmoghEngineers","Category":"Dress","Subcategory":"jeans","District":"7","Location":"India","Plan":"Gold","ProductOrService":"Product","Email":"[email protected]","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}]解析Json字符串到Html元素

我需要解析這些數據到html字段元素,例如:我想將名稱設置爲輸入字段$("#businessName").val(Name)。我怎樣才能做到這一點 ?提前致謝 。

回答

1

你可以像這樣做,

Live Demo

$("#businessName").val(jsonObjArray[0].Name) 

編輯如果你有這樣的字符串,你可以使用$ .parseJSON

jsonObjArray= $.parseJSON('[{"Row_id":"1","Name":"AmoghEngineers","Category":"Dress","Subcategory":"jeans","District":"7","Location":"India","Plan":"Gold","ProductOrService":"Product","Email":"[email protected]","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}]');  
$("#businessName").val(jsonObjArray[0].Name); 
+0

讓我試試這個 – Crazyrubixfan 2013-05-04 08:45:47

+0

var obj = jQuery.parseJSON(result); alert(obj [0] .Name)這可以,但在jsonObj上使用索引很好嗎? – Crazyrubixfan 2013-05-04 08:48:13

+0

你有對象數組,所以你需要使用索引,變量的名稱是令人困惑的,它會是jsonObjArray,檢查我更新的答案。 – Adil 2013-05-04 08:49:53

0
var data = '[{"Row_id":"1","Name":"AmoghEngineers","Category":"Dress","Subcategory":"jeans","District":"7","Location":"India","Plan":"Gold","ProductOrService":"Product","Email":"[email protected]","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}]' 

var json_data = JSON.parse(data) 
$("#businessName").val(json_data[0].Name) 
0

是的你必須這樣打電話

var jsonresponse_obj = JSON.parse(response);

jsonresponse_obj.Row_id to get value of row id and soo on