ravi404
ravi404

Reputation: 7309

decoding json from mysql result

I encoded a mysql result from php to json.. I need to decode it in javascript. Say my string returned is

[{"0":"x","1":"z"},{"0":"xs","1":"zz"}]

Please help me on how to get the value of a particular row and column.. for instance how to get the value of "0" of the second row.

EDIT:

Sorry for bothering friends my mistake.. the typeof returned as string JSON.parse(data) did the trick..

Upvotes: 0

Views: 429

Answers (2)

mplungjan
mplungjan

Reputation: 177692

Why make objects? It is very poor coding standard to NAME attributes with a number.

Since it obviously are arrays do this instead

var x = [["x","z"],["xs","zz"]]

Then

x[1][0] will give you xs

Upvotes: 0

Mike Ryan
Mike Ryan

Reputation: 4374

var data = [{"0":"x","1":"z"},{"0":"xs","1":"zz"}];
alert (data[1]["0"]);

gives you the xs

The [] represents an array structure, with each {} being an element in the array. Then, within each object there is a set of attributes, which you get it via the attribute's identifier. In this case, it's 0, so it could have just be 0 as well.

Upvotes: 1

Related Questions