我有一个像这样的Json字符串:[{"Row_id":"1","Name":"AmoghEngineers","Category":"Dress","Subcategory":"jeans","District":"7","Location":"India","Plan":"Gold","ProductOrService":"Product","Email":"mymail@gmail.com","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}]
。
我需要将这些数据解析为html字段元素,例如:我想将Name设置为输入字段$("#businessName").val(Name)
。我怎样才能做到这一点 ?提前谢谢。
答案 0 :(得分: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":"mymail@gmail.com","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}]');
$("#businessName").val(jsonObjArray[0].Name);
答案 1 :(得分:0)
var data = '[{"Row_id":"1","Name":"AmoghEngineers","Category":"Dress","Subcategory":"jeans","District":"7","Location":"India","Plan":"Gold","ProductOrService":"Product","Email":"mymail@gmail.com","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}]'
var json_data = JSON.parse(data)
$("#businessName").val(json_data[0].Name)
答案 2 :(得分:0)
是的,你必须这样打电话
var jsonresponse_obj = JSON.parse(response);
jsonresponse_obj.Row_id to get value of row id and soo on