我有这样的json字符串 {“common_search”:{“strBusinessName”:“Sun Shine Vision”,“strAddress”:“Amulia St Madhava Pharmacy Jn”,“intPhone”:“”},“cache_table”:{“详情”:“Speedtrax,Ample’s B
{“common_search”:{“strBusinessName”:“Sun Shine Vision”,“strAddress”:“Amulia St Madhava Pharmacy Jn”,“intPhone”:“”},“cache_table”:{“详情”:“Speedtrax,Ample’s Bldg Off Banerji Rd.,Amulia St,“}}
我必须将这些数据设置为我的html div,例如:我想将common_search数据设置为
$("#common_serachdiv").html('strBusinessName')
和cache_table数据到$(“#cache_table”).html(‘Details’),或者我必须迭代Json中的每个数组.这该怎么做 ,
提前致谢 .
您需要先解析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.