如何访问json数据

时间:2017-06-23 02:08:42

标签: javascript react-native

我目前遇到了问题,我无法找到解决方案。

我向REST服务请求并获取一些数据......

var test = responseData._bodyInit;
console.log(test);

06-23 03:43:14.383 12800 12832 I ReactNativeJS: {"search_time": 92, "results": [{"item": {"name": "Profil", "url": "https://www.someurl.tdl", "custom": "bla", "content": null, "trackable": false, "uuid": "otheruuid"}, "image": {"thumb_120": "morebla", "uuid": "someuuid"}, "score": 69}]}

到目前为止一切顺利,但我只想拥有“网址”......所以我试过了:

console.log(test['results'][0].item.url);

并收到以下日志:

06-23 03:43:14.398 12800 12832 I ReactNativeJS: { [TypeError: undefined is not an object (evaluating 'test['results'][0]')]

06-23 03:43:14.398 12800 12832 I ReactNativeJS: line: 1340,

06-23 03:43:14.398 12800 12832 I ReactNativeJS: column: 40,

06-23 03:43:14.398 12800 12832 I ReactNativeJS: sourceURL: 'http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false' }

0 个答案:

没有答案