Reputation: 2785
So I have this:
{"d":[{"__type":"Like","Id":345,"Sender":"JohnSmith","SourceId":338,"DateTime":"\/Date(1321057654000)\/","FromStream":true}]}
And this:
function LikesSuccess(result, userContext, methodName) {
for (var key in result) {
alert(key.Sender);
}
}
JSON returns an array of type "Like" with the properties shown above. Is there another way of getting "JohnSmith" from Sender? Because this returns undefined.
Thanks.
Upvotes: 0
Views: 1256
Reputation: 5579
Try
for (var i = 0; i < result.d.length; i++) {
alert(result.d[i].Sender);
}
because your JSON object has the key d
. >> jsfiddle
Upvotes: 2
Reputation: 7268
Try this code :
function LikesSuccess(result, userContext, methodName) {
for (var property in result.Properties) {
alert(result[property]);
}
}
I remember having used something similar, when I was working with Asp.Net Ajax, web services. Not sure about the correct syntax though.
Upvotes: 0
Reputation: 3501
use jquery
var obj = $.parseJSON(str)
Then you get the js object
Upvotes: 0