将json输出分配给reactjs中的javascript变量

时间:2018-05-26 13:17:27

标签: reactjs

将axios响应传递给变量时,JSON.parse或JSON.stringigy无法正常工作

 axios.get('api/v0/graph/instance/'+ this.props.selectedNode )
  .then(response => {
      console.log('Starting of tree node message' + response.data.message);
        //var message = JSON.parse(response.data.message);
      var RtnJSONVal = JSON.parse(response.data.message);

      console.log('value of the message variable is' + RtnJSONVal.length );
      var fields = RtnJSONVal;

response.data.message是如何在下面的值

{  
   "guid":"FCU1",
   "group_parent":"room_687",
   "p":{  

   },
   "ctime":1527225563237,
   "mtime":1527225563239,
   "instanceOf":"FCU",
   "coordinates":{  
      "type":"Point",
      "coordinates":[  
         32.76473,
         35.01616
      ],
      "crs":{  
         "type":"name",
         "properties":{  
            "name":"EPSG:4326"
         }
      }
   },
   "ref-in":[  
      {  
         "src":"FCU1_Extractor",
         "tgt":"FCU1",
         "refType":"hasAsset"
      },
      {  
         "src":"FCU1_Diffuser",
         "tgt":"FCU1",
         "refType":"hasAsset"
      }
   ],
   "ref-out":[  
      {  
         "src":"FCU1",
         "tgt":"room_687",
         "refType":"hasLocation"
      }
   ]
}

但是,当我尝试分配给变量时,我收到错误

消息变量的值是[object Object]"

0 个答案:

没有答案