0

I'm not a JavaScript programmer, and I'm trying to dabble in jquery.

I know that if I have string in the form:

var myList=[{"Tank1": 45000, "Tank2": -10}, {"Tank1": 200, "Tank2": 435}]

the javascript code which I've copied can read it, and use it.

My question, is how do I get the same list as a variable "myList", when it comes from JSON. My python server code outputs JSON as:

[{"Tank1": 45000, "Tank2": -10}, {"Tank1": 200, "Tank2": 435}]    

Could someone show me how I can read this into javascript as a variable "myList", please? Do I also need any specific .js libraries?

Gagravarr
  • 45,438
  • 10
  • 104
  • 147

1 Answers1

0

You can use $.parseJSON function to make it json object using jQuery.

$.parseJSON('[{"Tank1": 45000, "Tank2": -10}, {"Tank1": 200, "Tank2": 435}]');

OR

$.parseJSON(varibleContainingJsonString);
Adil
  • 143,427
  • 25
  • 201
  • 198