1

I have a Json string like this : [{"Row_id":"1","Name":"AmoghEngineers","Category":"Dress","Subcategory":"jeans","District":"7","Location":"India","Plan":"Gold","ProductOrService":"Product","Email":"mymail@gmail.com","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}] .

And i need to parse these data to the html field elements ,for eg: i want to set the Name to a input field $("#businessName").val(Name). How can i do this ? Thanks in advance .

KTM
  • 858
  • 4
  • 21
  • 43

3 Answers3

1

You can do it like this,

Live Demo

$("#businessName").val(jsonObjArray[0].Name)

Edit If you have this in string you can use $.parseJSON

jsonObjArray= $.parseJSON('[{"Row_id":"1","Name":"AmoghEngineers","Category":"Dress","Subcategory":"jeans","District":"7","Location":"India","Plan":"Gold","ProductOrService":"Product","Email":"mymail@gmail.com","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}]');    
$("#businessName").val(jsonObjArray[0].Name);
Adil
  • 146,340
  • 25
  • 209
  • 204
  • var obj = jQuery.parseJSON(result); alert(obj[0].Name)This works , but is it good to use indexing on the jsonObj ?? – KTM May 04 '13 at 08:48
  • You have array of objects so you need to use index, name of variable is confusing it would be jsonObjArray, check my updated answer. – Adil May 04 '13 at 08:49
  • okay fine ,let me workout – KTM May 04 '13 at 08:51
0
var data = '[{"Row_id":"1","Name":"AmoghEngineers","Category":"Dress","Subcategory":"jeans","District":"7","Location":"India","Plan":"Gold","ProductOrService":"Product","Email":"mymail@gmail.com","About":"goodone","Phone":"98675433","Registration_confirmed":"Yes"}]'

var json_data = JSON.parse(data)
$("#businessName").val(json_data[0].Name)
Akshar Raaj
  • 14,231
  • 7
  • 51
  • 45
0

yes you have to call like this way

var jsonresponse_obj = JSON.parse(response);

jsonresponse_obj.Row_id to get value of row id and soo on
liyakat
  • 11,825
  • 2
  • 40
  • 46