0

I have a vb.net webservice that produces a JSON string that I process using AJAX and JavaScript. Currently I build the string using Newtonsoft.Json and the JSON comes out looking like :

[{"NAME":"Richard","Description":"Richard

and I parse it using

     success: function (data) {    
     var = dataJson = JSON.parse(data.d); 

from my Success Function. I started trying JsonConvert.SerializeObject(ds) and it comes out like:

{"Results":[{"NAME":"Richard ","Description":"Richard.

My dataJson = JSON.parse(data.d);

is tripping on the "Results" I understand that I'm sterilizing a dataset on the server but need to know how to read the first results. Something like:

  dataJson = JSON.parse(data.d);
  var results = dataJson.[0] ?????
1
  • got it var req = JSON.parse(data.d); dataJson = req.Results; Commented Nov 26, 2016 at 1:40

1 Answer 1

2

First of all, you have in you question code the following that I hope is just a typo:

var = dataJson = JSON.parse(data.d); 

When it supposed to be:

var dataJson = JSON.parse(data.d); 

Second, when you serialize an object (or list, or array) in your backend, and de-serialize in Javascript, you are going to have the same object, just that now in javascript, so if is an array or list, you will be accesing the first element like this:

var results = dataJson[0];

Or:

var results = dataJson[0].something;

if you want to access some property.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect and thanks-- yup a little cut and paste problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.