Home > front end >  Ajax solution to obtain the background data variable type string
Ajax solution to obtain the background data variable type string

Time:09-24

Today suddenly meet ajax to get the data from the background changed into type string, how also can not get the inside of the json values in js, over value into d="{" rows" : [{" SaleTotal ": 28}, {" SaleTotal" : 7}, {" SaleTotal ": 1}, {" SaleTotal" : 36}], "total" : 4} ",
Added ", "don't know what reason cause behind d.r ows [0] [" SaleTotal"] how also can not get the value of the inside, then put a piece of code var e=JSON. Parse (d); To convert d after they get, above:

Workplace small white, and what a great god tell me why the value of the much more difficult to express "", I ajax in another function to get the value of the works, the background code is the same, no problem

CodePudding user response:

With or without the quotation marks can define your own, but JSON format specification is {" key ":" value "}, is to bring the double quotes, as far as possible in accordance with the specification do

CodePudding user response:

Json string turn json object
Var STR="{id: 1, name: 'test 1}"
Var obj=JSON. Parse (STR);
The console. The log (obj)//{id: 1, name: 'test 1}
The console. The log (obj. Id)//1
  •  Tags:  
  • Ajax
  • Related