我使用的HTTP客戶端從Apache和我試圖解析從我從客戶得到的迴應JSON數組。解析來自HTTP響應JSON數組在Java中
這是我接收回來的JSON的一個例子。
[{"created_at":"2013-04-02T23:07:32Z","id":1,"password_digest":"$2a$10$kTITRarwKawgabFVDJMJUO/qxNJQD7YawClND.Hp0KjPTLlZfo3oy","updated_at":"2013-04-02T23:07:32Z","username":"eric"},{"created_at":"2013-04-03T01:26:51Z","id":2,"password_digest":"$2a$10$1IE6hR4q5jQrYBtyxMJJBOGwSPQpg6m5.McNDiSIETBq4BC3nUnj2","updated_at":"2013-04-03T01:26:51Z","username":"Sean"}]
我正在使用http://code.google.com/p/json-simple/作爲我的json庫。
HttpPost httppost = new HttpPost("SERVERURL");
httppost.setEntity(input);
HttpResponse response = httpclient.execute(httppost);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))
Object obj=JSONValue.parse(rd.toString());
JSONArray finalResult=(JSONArray)obj;
System.out.println(finalResult);
這是我試過的代碼,但它不起作用。我不知道該怎麼做。任何幫助表示讚賞,謝謝。
如何在不工作?你在期待什麼?你得到了什麼? – John3136 2013-04-04 01:53:06
陣列打印null – user2044754 2013-04-04 01:57:03