1

I have a php web page returning json string. json string is like this .

   {
   "employees": [
   {
  "fname": "sdsdsd",
  "lname": "sdsd",
  "phone": "sdsd",
  "gender": "female",
  "dob": "1990-03-11",
  "address": "03",
  "nic": "erer",
  "email": "erererer",
  "empid": "ererere",
  "designation": "sdsds",
  "qualifications": "dsds"
 }
 ]

   }

this is a dynamic page (values can change). i want to display these strings in a jquery mobile listview. please tell me how should my javascript function looks like..

3
  • well it should start with <script> something goes here and end with </script> Commented Sep 25, 2013 at 5:49
  • stackoverflow.com/questions/18051227/… Commented Sep 25, 2013 at 5:51
  • you should return the value as JSON from your AJAX call, then it is as simple as var json_obj = ajax_result; Commented Sep 25, 2013 at 5:55

1 Answer 1

3

Append extra an [ and ] to the beginning and end of the string. This will make it an array.

jQuery:

var json = '{"id":1,"name":"Test1"},{"id":2,"name":"Test2"}';
var jsonArray = $.parseJSON('[' + json + ']');

JavaScript:

var jsonArray = eval('(' + json + ')');

Here is Jsfiddle Demo

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

Comments

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.