pravin
pravin

Reputation: 2155

How to parse .json file using jquery

I want to read .json file using jquery.

Please let me know your pointer in this.

Thanks,

Upvotes: 1

Views: 5083

Answers (3)

Quentin
Quentin

Reputation: 944443

  1. Fix the data so it conforms to the JSON specification
  2. Use getJSON

You won't get an Array though, not at the top level at least. That will be resolved as an Object (since it has named key-value pairs), not an Array. However, the value of the data property will be an Array.

Upvotes: 4

Alex
Alex

Reputation: 66042

First, technically that is not JSON, as all of your keys are not quoted. Second, it really depends on how you want the data formatted. If you want all of the objects in the data array to be formatted as key=value, you could do something like this:

var myArray = [];
$.each(yourJSONVar.data, function(index, object) {
    myArray.push(object.name + "=" + object.rollno);
});

Upvotes: 1

LeftyX
LeftyX

Reputation: 35597

$.parseJSON returns an array from a json object.

Upvotes: 1

Related Questions