从解析的JSON对象中获取元素

时间:2016-02-13 20:48:08

标签: javascript html json

我似乎无法提取已解析的JSON对象的元素。

var thisObj = JSON.parse(req.responseText);
   console.log(JSON.parse(req.responseText));

以下是记录的内容:

Object
data: "{"sVar":"sdf","nVar":"","dVar":"","cVar":"#000000"}"

我尝试过以下方法

thisObj.data[sVar]

thisObj.data.sVar

他们都制作了undefined

它似乎不在数组中。 有什么想法吗?

CONSOLE.LOG(req.responseText)...

{
  "args": {}, 
  "data": "{\"sVar\":\"asdf\",\"nVar\":\"\",\"dVar\":\"\",\"cVar\":\"#000000\"}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Accept-Language": "en-US,en;q=0.8", 
    "Content-Length": "52", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "Origin": "http://localhost:63342", 
    "Referer": "http://localhost:63342/AssignmentAJAX/weather.html", 
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"
  }, 
  "json": {
    "cVar": "#000000", 
    "dVar": "", 
    "nVar": "", 
    "sVar": "asdf"
  }, 
  "origin": "65.128.122.251", 
  "url": "http://httpbin.org/post"
}

1 个答案:

答案 0 :(得分:1)

{{my-component componentAttribute=foo anotherAttribute=bar}}的{​​{1}}属性是表示数据对象的字符串。你也应该解析它。例如:

data