blacktooth
blacktooth

Reputation: 306

How to parse a "Mysql result JSON String" in Javascript?

Is there a way to convert it into object form? So that each field of the result can be accessed results[i].field where i is the number of records in the mysql result..

This is my JSON String http://pastebin.com/Cky1va3K

Upvotes: 1

Views: 1778

Answers (2)

Syntactic
Syntactic

Reputation: 10961

Sure. That's what JSON is for, really; it stands for JavaScript Object Notation. A JSON object is a JavaScript object literal.

See the official JSON documentation on using JSON in JavaScript here. Some browsers have native support for JSON parsing (so you don't have to use eval()) and for those that don't, a JavaScript JSON parser is available for download from that page.

Upvotes: 2

Dormilich
Dormilich

Reputation: 927

if you paste this string serverside into JavaScript code, it is converted automatically.

var myResult = { "result" : /* etc.*/ };
alert(myResult.result[0].REPORT); // see the result

Upvotes: 0

Related Questions