2013-08-21 41 views
0

我有一個調用URL的JSON功能,並顯示它在提示味精含量,函數工作我測試了蒙山這個網址:http://date.jsontest.com/JSON HttpRequest的語法

,但我不得不這樣做有此內容的網址://這是一個Java文件類

reponse_tex="{ id:" + p_id + ",Categorie: "+ p_demandAide.getP_categorie()+ ",Type: " +p_demandAide.getP_type() +",Message: " +p_demandAide.getP_message()+",Reponse: " +p_demandAide.getP_response() + " }"; 

我班的作品,它顯示了我在瀏覽器中的內容,但我知道我必須把它寫在一個格式,以便JSON瞭解它就像第示例url ... 但我很難添加(「」)java不允許它在它的語法。

+0

什麼做轉義你的意思是java不會允許它?你的意思是你必須逃避它嗎? –

+0

它給了我語法錯誤,當我想添加(「」) – neustre

+0

@你可以發佈它看起來像什麼嗎?還是上面那個? –

回答

0

JSON是有關語法很清楚。請參閱http://www.json.org/您需要圍繞字符串值鍵名稱使用雙引號。 {"like": "this", "see?": true}(如果你需要一個字符串值雙引號,你用反斜槓轉義:{"this": "has \"literal\" quotes"}

至於用Java編寫一個字符串文字,在它有雙引號,你用反斜槓"like \"this\", see?"

+0

非常感謝你@Rob Starling – neustre

+0

np!我真的覺得這個流程圖(在json.org上)是一個很好的視覺參考。 –

+0

另一件可以輕易捕捉到你的東西就是尾隨逗號。不像Python(例如),'{「這個」:「是無效的,}' –

0

所以看來你正在尋找逃避報價。所以做這個

reponse_tex="{\"id\":\"" + p_id + "\",\"Categorie\": \""+ 
p_demandAide.getP_categorie()+ "\",\"Type\": \"" +p_demandAide.getP_type() 
+"\",\"Message\": \"" +p_demandAide.getP_message()+"\",\"Reponse\": \"" 
+p_demandAide.getP_response() + "\" }"; 

更新

躲過圍繞重點太恩的報價。 \「ID \」 ...... 發現其中的差別,如果我不逃避報價ID,catagorie不再APRT字符串的

reponse_tex="{"id":\"" + p_id + "\","Categorie": \""+ 
p_demandAide.getP_categorie()+ "\","Type\": "" +p_demandAide.getP_type() 
+"\","Message": \"" +p_demandAide.getP_message()+"\","Reponse": \"" 
+p_demandAide.getP_response() + "\" }"; 
+0

仍然告訴我:這條線上有多個標記。 – neustre

+0

@nuestre LOL逃脫id等之間的報價 –

+0

非常感謝你 – neustre