2017-06-23 14 views
0

現在、問題が発生しており、解決策を見つけることができません。jsonデータへのアクセス方法

私はので、私が試した... 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}]} 

をこれまでのところは良いが、私は唯一の「URL」を持つようにしたい:

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

おそらく 'test'はまだ解析されていないJSON文字列ですか? 'JSON.parse(test).results [0] .item.url'を試してみてください。 – smarx

+0

'console.log(typeof(test))'を使って確認してみてください。 – smarx

+0

ありがとうございました!それは文字列だった。 – Marq

答えて

0

これはそれを行います。

var url = JSON.parse(j).results[0].item.url; 
関連する問題