使用jquery将Json字符串解析为html div

时间:2013-04-25 07:57:43

标签: jquery json

我有像这样的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中的每个数组。怎么做,

提前致谢。

1 个答案:

答案 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.