Home > front end >  Small white one, consult a Json parsing is unknown
Small white one, consult a Json parsing is unknown

Time:10-01

Had A little problem, the younger brother is self-study JS, grasp the following Json is net return of data, but I want to get A, B, C, D value, don't know how to extract,
Please teach a great god, no appreciate,
{" time ": {" 2020-02-08" : {" A ": 200," B ": 400," C ": 150, the" D ": 360}}}

CodePudding user response:

 var s=` {" time ": {" 2020-02-08" : {" A ": 200," B ": 400," C ": 150, the" D ": 360}}} `; 
S=` (${s}) `;
Var obj=eval (s);
Var {A, B, C, D}=obj. Time (" 2020-02-08 ");
The console. The log (A, B, C, D);

CodePudding user response:

Sometimes will suddenly stupid head ha, the answer is better:
 var json `={" time ": {" 2020-02-08" : {" A ": 200," B ": 400," C ": 150, the" D ": 360}}} `; 
Var obj=JSON. Parse (JSON);
Var {A, B, C, D}=obj. Time (" 2020-02-08 ");
The console. The log (" as you can see: ", A, B, C, D);

CodePudding user response:

 var s='{" time ": {" 2020-02-08" : {" A ": 200," B ": 400," C ": 150, the" D ": 360}}}'; 
The eval (" var obj="+ s);
Var a=obj. Time [r]. "the 2020-02-08" a;
Alert (a);

CodePudding user response:

Great god or more ah, gives so much so quickly the correct answer, thank you,
  • Related