0

我有一个 jsonObject,我想将它传递给一个 web 服务,该 jsonObject 将成为动态样本 -

{"data1":"data1data","data2":"data2data"}

那么如何将其转换为 JSONArray 并提前发送谢谢

4

1 回答 1

1
JSONObject json = new JSONObject("{"data1":"data1data","data2":"data2data"}");
JSONArray array = new JSONArray();
array.put(json);

要将该数组放入 HTTP 调用中,例如发布:

DefaultHttpClient client = new DefaultHttpClient();
HttpPut put = new HttpPut(uri); 
put.setEntity(new StringEntity(array.toString()));
put.setHeader("content-type", "application/json");
httpResponse = client.execute(put);
于 2013-10-30T11:12:44.667 回答