检查的Json在Web服务 [英] Checking Json in a web service

查看:139
本文介绍了检查的Json在Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON的一个问题。 我希望我的JSON来是这样的:

I have a problem with json. I want my Json to look like:

 data={"phoneId":1,"token":"APA91bF2tN5g1TtULFE5tysRMAarygjX4w9hjTGCqT3SL-PwiMV6aqTtkV3lpqLkc7msVfEdTnyd_pJVFNMM_fjEbeVSuCjiNPVKx7p9sYC1DoWnuKUurt31E1yh2RDwl_oprfKxEF18PP6Q8dXHZe6FeflE3CIxBg","appId":5}

这是我的岗位,以Web服务:

This is my post to web service:

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);

我如何检查我的JSON看起来像一个在我的例子吗?我想检查我的怎么是JSON岗位web服务。

How can I check if my json looks like one in my example? I want to check how my json is post to webservice.

推荐答案

尝试为:

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()));

这将创建JSON对象为:

this will create your JSON object as:

data={
  "phoneId": 1,
  "token": "token",
  "appId": 5
}

这篇关于检查的Json在Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆