2
[ { "regNo": "1", "regDate": "2025-05-12", "patientName": "Ratna", "address": "saasgasgasga", "city": "Hyderabad", "phno": "2147483647", "mrgStatus": "single" } ] 

this comes from server to client i'm using jQuery.parseJSON()method to parse the data but it doesn't work.. can any one help me how to parse it...???

my code is like this..

success:function(data) { var myObject = jQuery.parseJSON(data); $("#patname").val(myObject.patientName); $("#guaname").val(myObject.fathername); $("#age").val(myObject.age); $("#addr").val(myObject.address); } 

but this displays empty...

1
  • 2
    Did you know that you only have to write jQuery in its long form once? By wrapping your code in (function($) { .... })(jQuery);, you can use $ no matter if noConflict has been used or not. Commented May 26, 2012 at 9:26

2 Answers 2

5

It already has been converted from JSON to an object - you don't need to parse it again.

success:function(data) { $("#patname").val(data[0].patientName); $("#guaname").val(data[0].fathername); $("#age").val(data[0].age); $("#addr").val(data[0].address); } 
Sign up to request clarification or add additional context in comments.

8 Comments

"It already is JSON formatted" --- well, it depends, but in this case most likely it is
True, I supposed I should say it's already been converted from JSON to an object.
if i use $("#patname").val(data[0].patientName); it will print NULL
If you put the following in your success handler, what do you see in the console: console.log(data[0]); ?
if i use $("#guaname").val(data[0]); it will print " [ "
|
0
 success: function(data) { // here data is an array, so you need data[0] to get the object $("#patname").val(data[0].patientName); $("#guaname").val(data[0].fathername); $("#age").val(data[0].age); $("#addr").val(data[0].address); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.