My web service is returning a JSON array called jsonString. I am using jQuery mobile. This has the value:
{
"id": "10844",
"password": "acddcd",
"role": ["PortalAdmin,ViewAllJob,SetupAdmin,Budget Approval,MarketingAdmin,ProjectManagementAdmin,HRAdmin,PayRollAdmin,SCMAdmin,VendorPortalAdmin,FinanceAdmin,AnalyticsAdmin"],
"userName": "portaluser"
}
What displaying this array in a text box (where #as is the text box):
$('#as').val(jsonString);
When I use this code :
var a = {
"id": "10844",
"password": "acddcd",
"role": ["PortalAdmin,ViewAllJob,SetupAdmin,Budget Approval,MarketingAdmin,ProjectManagementAdmin,HRAdmin,PayRollAdmin,SCMAdmin,VendorPortalAdmin,FinanceAdmin,AnalyticsAdmin"],
"userName": "portaluser"
};
alert(a.id);
I get the right answer i.e. 10844 However, when I use this code:
var a=jsonString;
alert(a.id);
I get undefined. Why?
ajaxthen you can adddataType: "JSON"parameter to request.