-2
我在外幣一個android.I應用具有獲取從服務器端期運用JSON數據,但我proble如何發送JSON字符串或JSO服務器如何發送JSON字符串到服務器端在Android中
我在外幣一個android.I應用具有獲取從服務器端期運用JSON數據,但我proble如何發送JSON字符串或JSO服務器如何發送JSON字符串到服務器端在Android中
您可以創建JsonObject ,將數據放入它,然後將其轉換爲String()進行發送。如何發送本身取決於您的服務器。 另請參閱question。
如果您的數據很大,我會建議您使用快速解析器。我使用Jackson。 你可以找到相關的代碼。與傑克遜,你可以使用對象映射器默認地圖轉換
ObjectMapper objectMapper = new ObjectMapper();
httppost.addData("points", getMapper().writeValueAsString(points));
InputStream instream = httpclient.execute(httppost).getEntity().getContent();
return getMapper().readValue(instream, HashMap.class);
我已經用一些代碼示例回答了類似的問題。請檢查['這個答案'](http://stackoverflow.com/questions/8950279/save-posts-to-rails-server-from-java-android-application-with-devise-authentica/8950868#8950868)。 – AD14