解析Json字符串到Html元素
问题描述:
我有一个像这样的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)
。我怎样才能做到这一点 ?提前致谢 。
答
你可以像这样做,
$("#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);
答
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)
答
是的你必须这样打电话
var jsonresponse_obj = JSON.parse(response);
jsonresponse_obj.Row_id to get value of row id and soo on
让我试试这个 – Crazyrubixfan 2013-05-04 08:45:47
var obj = jQuery.parseJSON(result); alert(obj [0] .Name)这可以,但在jsonObj上使用索引很好吗? – Crazyrubixfan 2013-05-04 08:48:13
你有对象数组,所以你需要使用索引,变量的名称是令人困惑的,它会是jsonObjArray,检查我更新的答案。 – Adil 2013-05-04 08:49:53