我做一個winJS.xhr這樣的JSON解析:如何在Windows 8
var jsonResult;
WinJS.xhr(
{
url: urlGoogle,
responseType: 'json'
}
).done(function complete(response) {
jsonResult = response.responseText;
console.log(jsonResult);
},
//Error and Progress functions
);
控制檯日誌顯示我:
{lhs: "32 Japanese yen",rhs: "0.30613818 Euros",error: "",icc: true}
而且我想要得到的RHS信息。 於是,我試着做
console.log(jsonResult.rhs);
和
console.log(jsonResult['rhs']);
那隻能說明我的 「不確定」。然後我意識到,當我做了一個jsonResult [0]時,它顯示了索引括號中的第一個字符(這是{)等等。
我試圖做一個JSON.parse(jsonResult);但它創建了一個錯誤
json parse unexpected character
你可以簡單地解析它在JavaScript obj = JSON.parse(json); json是json的對象...... – AurA
@AurA:這沒有用,他在他的問題的最後一行中是這樣說的。 – Cerbrus
json解析意外字符是由於解析已解析的對象...不是解析JSON字符串可以在[this post]中找到更多幫助(http://stackoverflow.com/questions/8524933/json-parse -unexpected-character-error) – AurA