ext_json 打印如下:
{\"ext\":{},\"networkTimeout\":{},\"directCommit\":false,\"extAppid\":\"wx09790aaa217db4b6\",\"tabBar\":{\"backgroundColor\":\"#fff\",\"color\":\"#646464\",\"selectedColor\":\"#47ad34\",\"list\":[{\"selectedIconPath\":\"images/tab-f01-on.png\",\"text\":\"\u9996\u9875\",\"pagePath\":\"pages/index/index\",\"iconPath\":\"images/tab-f01.png\"},{\"selectedIconPath\":\"images/tab-f02-on.png\",\"text\":\"\u5206\u7C7B\",\"pagePath\":\"pages/fenlei1/fenlei1\",\"iconPath\":\"images/tab-f02.png\"},{\"selectedIconPath\":\"images/tab-f03-on.png\",\"text\":\"\u8D2D\u7269\u8F66\",\"pagePath\":\"pages/shopCar/shopCar\",\"iconPath\":\"images/tab-f03.png\"},{\"selectedIconPath\":\"images/tab-f04-on.png\",\"text\":\"\u6211\u7684\",\"pagePath\":\"pages/userCenterMall/userCenterMall\",\"iconPath\":\"images/tab-f04.png\"}]},\"extPages\":{},\"window\":{\"navigationBarBackgroundColor\":\"#fff\",\"navigationBarTitleText\":\"WeChat\",\"navigationBarTextStyle\":\"black\",\"backgroundTextStyle\":\"light\"},\"extEnable\":true}
查了好久了,不知道哪里有问题!求大婶们帮忙看看!
doPosting的代码看一下。还有你这是一直有错,还是偶尔有错?
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String ret = "";
try {
HttpPost httpPost = new HttpPost(url);
HttpEntity entityReq = new StringEntity(parameter,
CharsetUtils.get("utf-8"));
httpPost.setEntity(entityReq);
httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8");
response = httpclient.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
ret = EntityUtils.toString(entity);
EntityUtils.consume(entity);
ret = new String(ret.getBytes("iso8859-1"), "utf-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close(response, httpclient);
}
return ret;
}
"access_token":"31_****",
"user_version":"v1.0.1",
"user_desc":"团购小程序",
"ext_json":"{"ext":{},"networkTimeout":{},"directCommit":false,"extAppid":"wx09790aaa217db4b6","tabBar":{"backgroundColor":"#fff","color":"#646464","selectedColor":"#47ad34","list":[{"selectedIconPath":"images/tab-f01-on.png","text":"首页","pagePath":"pages/index/index","iconPath":"images/tab-f01.png"},{"selectedIconPath":"images/tab-f02-on.png","text":"分类","pagePath":"pages/fenlei1/fenlei1","iconPath":"images/tab-f02.png"},{"selectedIconPath":"images/tab-f03-on.png","text":"购物车","pagePath":"pages/shopCar/shopCar","iconPath":"images/tab-f03.png"},{"selectedIconPath":"images/tab-f04-on.png","text":"我的","pagePath":"pages/userCenterMall/userCenterMall","iconPath":"images/tab-f04.png"}]},"extPages":{},"window":{"navigationBarBackgroundColor":"#fff","navigationBarTitleText":"WeChat","navigationBarTextStyle":"black","backgroundTextStyle":"light"},"extEnable":true}",
"template_id":"1"
}
public static String post(String url, String json) throws IOException {
RequestBody body = RequestBody.create(json, JSON);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
return Objects.requireNonNull(response.body()).string();
}
}
格式化的代码:
{
"ext":{
},
"networkTimeout":{
},
"directCommit":false,
"extAppid":"wx09790aaa217db4b6",
"tabBar":{
"backgroundColor":"#fff",
"color":"#646464",
"selectedColor":"#47ad34",
"list":[
{
"selectedIconPath":"images/tab-f01-on.png",
"text":"首页",
"pagePath":"pages/index/index",
"iconPath":"images/tab-f01.png"
},
{
"selectedIconPath":"images/tab-f02-on.png",
"text":"分类",
"pagePath":"pages/fenlei1/fenlei1",
"iconPath":"images/tab-f02.png"
},
{
"selectedIconPath":"images/tab-f03-on.png",
"text":"购物车",
"pagePath":"pages/shopCar/shopCar",
"iconPath":"images/tab-f03.png"
},
{
"selectedIconPath":"images/tab-f04-on.png",
"text":"我的",
"pagePath":"pages/userCenterMall/userCenterMall",
"iconPath":"images/tab-f04.png"
}
]
},
"extPages":{
},
"window":{
"navigationBarBackgroundColor":"#fff",
"navigationBarTitleText":"WeChat",
"navigationBarTextStyle":"black",
"backgroundTextStyle":"light"
},
"extEnable":true
}