D.B D.B - 2 months ago 9x
Ajax Question

Get value from an odata property in a JSON response using ajax

I need to get the value for @odata.context property from the following Json response in ajax:


I would like to do something like that in code:

type: "POST",
beforeSend: function (request) {
request.setRequestHeader("Authorization", 'Bearer ' + bearerToken);
url: serverUrl,
data: JSON.stringify(params),
dataType: 'json',
contentType: " application/json",
success: function (data) {
var myvalue= data.@odata.context; // ****???
var jsonObject = JSON.parse(data); //this line throws an error Unexpected token o in JSON at position 1



I think you can get data by this:


And about the JSON.parse throw exception, it caused by the data is not a JSON string.