jquery - How to access JSON Object name/value? -
function (data) { //add values based on activity type //data = json.parse(data); //alert(abc.phone1); alert(data.myname) alert(data.tostring()); if (activitytype == "phone") { } return; }, as can see callback function of $.ajax taking json data controller.
for example:
[{"name":"myname" ,"address": "myaddress" }]
in case first alert giving me undefined , second/third alert popup comes with:
[{"name":"myname" ,"address": "myaddress" }]
how can access value name first alert filled out myname value of name?
in stead of parsing json can followng:
$.ajax({ .. datatype: 'json' // using json, jquery make parse }); to access property of json following:
data[0].name; data[0].address; why need data[0] because data array, content retrieve need data[0] (first element), gives object {"name":"myname" ,"address": "myaddress" }.
and access property of object rule is:
object.property or sometimes
object["property"] // in case so need
data[0].name , on want.
if not
set datatype: json need parse them using $.parsejson() , retrieve data above.
Comments
Post a Comment