저는 RaspberryPi에서 NodeJS를 사용하는 학교 프로젝트 용 전기 엔지니어입니다. 필자는 객체 지향 프로그래밍에 대한 아이디어에 익숙하지 않고 JSON 객체에서 특정 값을 가져 오는 데 문제가 있습니다.JSON에서 값을 얻을 수 없습니다
var wolfram = require('wolfram').createClient("[CENSORED]")
wolfram.query("integrate 2x", function(err, result) {
if(err) throw err
console.log("Result: %j", result)
})
그것은 다음과 같은 JSON 반환 :
[
{
"subpods":
[{
"title":"",
"value":" integral 2 x dx = x^2+constant",
"image":"http://www5a.wolframalpha.com/Calculate/MSP/MSP36002050fgg595dgib5a000031a456025754352g?MSPStoreType=image/gif&s=59"
}],
"primary":true
},
{
"subpods": [{
"title":"",
"value":"",
"image":"http://www5a.wolframalpha.com/Calculate/MSP/MSP36012050fgg595dgib5a000055e24iecig9cc4ga?MSPStoreType=image/gif&s=59"
}],
"primary":false
}
]
난에서 "값"을 얻으려고을
내 프로그램은 다음 코드를 사용하여 객체 "결과"를 반환 울프 럼 알파를 조회 첫 번째 하위. 나는 시도 : var newResults = result.subpods[0].value;
그러나 이것은 나에게 오류를 준 : TypeError: Cannot read property '0' of undefined
내가 적어도 지난 시간 동안 서로 다른 조합을 시도했습니다. 도와주세요!
은, 시간 내 주셔서 감사Bobbyg
: http://stackoverflow.com/questions/5726729/ how-to-parse-json-using-nodejs – Jack