在Web服务中检查Json

use*_*569 5 android json

我和json有问题.我希望我的Json看起来像:

 data={"phoneId":1,"token":"APA91bF2tN5g1TtULFE5tysRMAarygjX4w9hjTGCqT3SL-PwiMV6aqTtkV3lpqLkc7msVfEdTnyd_pJVFNMM_fjEbeVSuCjiNPVKx7p9sYC1DoWnuKUurt31E1yh2RDwl_oprfKxEF18PP6Q8dXHZe6FeflE3CIxBg","appId":5}
Run Code Online (Sandbox Code Playgroud)

这是我的帖子到网络服务:

JSONObject jsonObject = new JSONObject();
                     jsonObject.put("token", regId);
                     jsonObject.put("appId", GlobalConfig.getAPPLICATION_ID());
                     jsonObject.put("phoneId", 1);

                     JSONArray jArrayParam = new JSONArray();
                     jArrayParam.put(jsonObject);

                     JSONObject finaljsonobj = new JSONObject();

                     finaljsonobj.put("data", jArrayParam);

                System.out.println(jsonObject.toString());
                List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
                nameValuePair.add(new BasicNameValuePair("Token",jArrayParam.toString()));

                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(GlobalConfig.getSendEmail());
                  httppost.addHeader("Authorization", "Basic " + Base64.encodeToString(
                            (GlobalConfig.getAuthString()).getBytes(),Base64.NO_WRAP));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePair, HTTP.UTF_8));

                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);
Run Code Online (Sandbox Code Playgroud)

如何在我的例子中检查我的json是否像一个?我想查看我的json如何发布到webservice.

ρяσ*_*я K 2

尝试如下:

JSONObject jsonObject = new JSONObject();
jsonObject.put("token", regId);
jsonObject.put("appId", GlobalConfig.getAPPLICATION_ID());
jsonObject.put("phoneId", 1);

System.out.println("data="+jsonObject.toString());
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("Token","data="+jsonObject.toString()));
Run Code Online (Sandbox Code Playgroud)

这将创建您的 JSON 对象:

data={
  "phoneId": 1,
  "token": "token",
  "appId": 5
}
Run Code Online (Sandbox Code Playgroud)