2017-03-02 20 views
0

對不起,如果這是一個愚蠢的問題。我正在嘗試使用另一個項目的API向服務器發出一些請求。服務器返回的JSON數據具有以下格式:{ "head": { "link": [], "vars": [ "s", "p", "o" ] },"results": { "distinct": false, "ordered": true, "bindings":等等。然而,當我撥打電話,通過我的項目在流星的反應是這樣的"\n{ \"head\": { \"link\": [], \"vars\": [ \"s\", \"p\", \"o\" ] },\n \"results\": { \"distinct\": false, \"ordered\": true, \"bindings\": 我的代碼看起來像這樣從服務器調用中檢索到的正確格式的JSON數據

Meteor.call("getURL",'serverURL',{},function(err,res){ 
    if(err){ 
     alert('Query not found: '+err); 
    } 
    if(!err){ 
     onsole.log(JSON.stringify(res)); 
    } 
} 

我怎麼能顯示從服務器沒有\ n和\等反應?

+1

的反應已經是一個字符串。嘗試'console.log(res)'而不是'console.log(JSON.stringify(res));' – blo0p3r

回答

1

它發生是因爲你的JSON.stringify結果(它已經是一個字符串)。請僅嘗試console.log(res)

嘗試打開一個瀏覽器控制檯,然後輸入:

const x = { "head": { "link": [], "vars": [ "s", "p", "o" ] }} 
console.log(JSON.stringify(JSON.stringify(x))); // same result 
+0

是的,這是做的伎倆。事情是,只是console.log(水庫)返回[對象對象]我用res.content和工作。謝謝! – PetrosM

+0

如果它工作,那麼你可以標記我的答案是正確的答案,謝謝。 – sonlexqt

+0

我試過了,但需要等待5分鐘 – PetrosM

相關問題