3

I have json string like this

{"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,"}}

And i have to set these data to my html divs for eg: i want to set common_search data to

$("#common_serachdiv").html('strBusinessName') 

and cache_table data to $("#cache_table").html('Details') , Or i have to iterate through each array inside Json . How to do this ,

Thanks in advance .

2
  • Does this question have something to do with php? Commented Apr 25, 2013 at 7:59
  • NO i have to iterate this json string in javascript only Commented Apr 25, 2013 at 8:01

1 Answer 1

8

You need to parse json before to use it.

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad to help you. Please don't forget to accept my answer by clicking the checkmark to the left of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.