2012-07-16 43 views
0

我遇到問題,解析了我從Google產品中的產品查詢中收到的數據。如果我運行類似的查詢......如何消費Google API JSON數據Google產品

curl --header "Authorization:GoogleLogin Auth=<AuthKey>" --header "Content-Type:application/atom+xml" https://content.googleapis.com/content/v1/8076653/items/products/generic?alt=json 

這是我收到一個JSON(英語?)文件,類似於以下

{ 
    "version":"1.0", 
    "encoding":"UTF-8", 
    "feed":{ 
    ... 
    } 
} 

但是當我運行以下

res.on('end', function() { 
    console.log(res.body.feed); 
    mainRes.send(res.body); 
}); 

控制檯顯示未定義。

+0

嘗試登錄'res.body',並從那裏工作了結構 – Esailija 2012-07-16 19:33:56

回答

0

應該是...

res.on('end', function() { 
    console.log(JSON.parse(res.body).feed); 
    mainRes.send(res.body); 
});