我得到一個錯誤,當我解析JavaScript中的json字符串。 「未捕獲的SyntaxError:意外的令牌Z」我知道它的「源」標記中的雙重qoutes,但我該如何解析?javascript json解析錯誤Doubleqoutes
<script type="text/javascript">
var data = '[ { "Outcome": "Success", "Message": null, "Identity": "Request", "Delay": 0.115825, "BaseCurrency": "EUR", "QuoteCurrency": "USD", "Symbol": "EURUSD", "Date": "10/07/2015", "Time": "2:46:32 PM", "QuoteType": "Spot", "Bid": 1.12394, "Mid": 1.12397, "Ask": 1.124, "Spread": 0.00006, "Text": "1 European Union euro = 1.12397 United States dollars", "Source": "SIX Financial Information, Buyer = \"ZKB Zuercher Kantonalbank, Devisen\", Seller = \"ZKB Zuercher Kantonalbank, Devisen\"" }, { "Outcome": "Success", "Message": null, "Identity": null, "Delay": 0, "BaseCurrency": "GBP", "QuoteCurrency": "USD", "Symbol": "GBPUSD", "Date": "10/07/2015", "Time": "2:46:32 PM", "QuoteType": "Spot", "Bid": 1.5293, "Mid": 1.5295, "Ask": 1.5297, "Spread": 0.0004, "Text": "1 British pound sterling = 1.5295 United States dollars", "Source": "SIX Financial Information, Buyer = \"UBS Investment Bank\", Seller = \"UBS Investment Bank\"" } ]';
var obj = JSON.parse(data);
for(var key in obj){
console.log(obj[key].Symbol);
}
</script>
我可以使用替換方法,但那不是一個乾淨的解決方案,我認爲。
使用'\「'引用字符串內,你在'Source'是法律有見json.org –
''\''是字符串字面特殊字符*和*。 JSON。在字符串文字中使用JSON並不常見,爲什麼在這裏首先使用JSON? –