My data on server is in the form of JSON array of objects. If I want to print the first object, how can I access its first object? Format of data is:
TypeScript
[ { "eventId": "8577",
"datasetId": "34",
"nodeId": "8076",
"typeId": "4",
"type": "TempAndHum",
"status": "Temp : 35, Hum : 83",
"datasetName": "test active set",
"mode": "shared",
"xmlFragment": "Absent",
"gpsLat": "-23.549999",
"gpsLong": "-46.633301",
"contributor": "SanatIITD",
"addedOn": "2015-04-21 08:03:16",
"updatedOn": "2015-04-21 08:03:16" },
{ "eventId": "8576",
"datasetId": "34",
"nodeId": "8076",
"typeId": "4",
"type": "TempAndHum",
"status": "Temp : 34, Hum : 81",
"datasetName": "test active set",
"mode": "shared",
"xmlFragment": "Absent",
"gpsLat": "-23.549999",
"gpsLong": "-46.633301",
"contributor": "SanatIITD",
"addedOn": "2015-04-21 08:03:11",
"updatedOn": "2015-04-21 08:03:11" },
{ "eventId": "8575",
"datasetId": "34",
"nodeId": "8076",
"typeId": "4",
"type": "TempAndHum",
"status": "Temp : 33, Hum : 80",
"datasetName": "test active set",
"mode": "shared",
"xmlFragment": "Absent",
"gpsLat": "-23.549999",
"gpsLong": "-46.633301",
"contributor": "SanatIITD",
"addedOn": "2015-04-21 08:03:05",
"updatedOn": "2015-04-21 08:03:05" },
]
I tried with data[0], but end up with printing "[". I tried with JSON.stringify also and then split with "," but that gives me first element
of the object, not the whole first object. I need to print the whole first object. Please suggest me some solution. Thanks in advance.| Part of my code is: |
$.ajax({ type: 'GET', url: "resource.php",
success:function(data){
alert(data);
var myData = JSON.parse(data);
document.getElementById("aami").innerHTML= myData[0]; }
});
Not getting where I am wrong? When I run this code I am getting [ object object]

Hemlata KushwahaRank #6,963 · 252 reputationPosted Aug 26, 2015, 1:56 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 25, 2015, 11:41 PM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Aug 25, 2015, 11:42 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 26, 2015, 1:57 AM EDT
Archana Roy13 reputationPosted Aug 26, 2015, 12:45 AM EDT
Archana Roy13 reputationPosted Aug 26, 2015, 12:48 AM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Aug 26, 2015, 12:56 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 26, 2015, 1:17 AM EDT
Archana Roy13 reputationPosted Aug 26, 2015, 1:20 AM EDT
Archana Roy13 reputationPosted Aug 26, 2015, 1:21 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 26, 2015, 1:27 AM EDT
function GetDayWiseDetail_Test() {
var Status;
$.ajax({
type: "POST",
url: ResolveUrl("~/WebMethods.aspx/GetDayWiseDetail_test"),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data) {
Status = data.d;
alert(Status)
},
failure: function (errMsg) {
}
});
return Status;
}
if you want to alert then use above oralert(data.Id);//Id is json key which return
Hemlata KushwahaRank #6,963 · 252 reputationPosted Aug 26, 2015, 1:36 AM EDT
Archana Roy13 reputationPosted Aug 26, 2015, 1:41 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 26, 2015, 1:46 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 26, 2015, 4:23 AM EDT
Archana Roy13 reputationPosted Aug 26, 2015, 9:05 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 26, 2015, 9:08 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 26, 2015, 10:10 PM EDT