我有像这样的json字符串
{"common_search":{"strBusinessName":"Sun Shine Vision","strAddress":"Amulia St Madhava Pharmacy Jn","intPhone":""}, "cache_table":{"Details":"Speedtrax,Ample's Bldg Off Banerji Rd., Amulia St,"}}
我必须将这些数据设置为我的html div,例如:我想将common_search数据设置为
$("#common_serachdiv").html('strBusinessName')
和cache_table数据到$("#cache_table").html('Details')
,或者我必须迭代Json中的每个数组。怎么做,
提前致谢。
答案 0 :(得分:7)
您需要parse json
才能使用它。
var obj = $.parseJSON('{"common_search":{"strBusinessName":"Sun Shine Vision","strAddress":"Amulia St Madhava Pharmacy Jn","intPhone":""}, "cache_table":{"Details":"Speedtrax,Ample\'s Bldg Off Banerji Rd., Amulia St,"}}');
$("#common_serachdiv").html(obj.common_search.strBusinessName);
$("#cache_table").html(obj.cache_table.Details);
<强> Fiddle Demo. 强>