传输一维的好说

    public static String  doPost(String url) {
String result = new String();
OutputStream out = null;
InputStream in = null;
try {
URL realUrl = new URL(url);
HttpURLConnection urlConnection = (HttpURLConnection) realUrl.openConnection();
urlConnection.setConnectTimeout();//设置连接超时
urlConnection.setReadTimeout();
// urlConnection.setRequestProperty("ser-Agent", "Fiddler");
urlConnection.setRequestProperty("connection", "Keep-Alive");
//urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//urlConnection.setRequestProperty("Content-Type", "text/html; charset=UTF-8");
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestMethod("POST");
// 发送POST请求必须设置如下两行
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setChunkedStreamingMode();
// 获取URLConnection对象对应的输出流
out = new BufferedOutputStream(urlConnection.getOutputStream());
// 发送请求参数
// String postContent =
// URLEncoder.encode("userName", "UTF-8") + "=" +
// URLEncoder.encode("admin", "UTF-8") + "&" +
// URLEncoder.encode("passWord", "UTF-8") + "="+
// URLEncoder.encode("admin", "UTF-8") ; JSONObject jsonObject = new JSONObject();
jsonObject.put("cmd","mobile");
jsonObject.put("param","00000000000");
Data = jsonObject.toString(); //String json = java.net.URLEncoder.encode(jsonObject.toString(), "utf-8"); Log.e("数据", Data ); // String postContent ="cmd="
// +URLEncoder.encode("check_mobile", "utf-8") + "&" +
// "mobile="+
// URLEncoder.encode("18363890557", "utf-8"); //Log.e("err",postContent); out.write(Data.getBytes());
out.flush();
out.close();
if (urlConnection.getResponseCode() == ) {
InputStreamReader inputStreamReader = new InputStreamReader(urlConnection.getInputStream(),"UTF-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String ee=null;
while ((ee = bufferedReader.readLine())!=null)
{
result = ee;
Log.e("err","接收到数据="+result);
}
}else {
result = null;
}
} catch (Exception e) {
Log.e("err",e+"");
} finally {//使用finally块来关闭输出流、输入流
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}

然后直接用任务

new Thread(new Runnable() {
@Override
public void run () { String sss = doPost("http://具体的地址");
//Log.e("err","Read="+sss);
}
}).start();

现在说二维的

假设要封装成这样

{ "cmd":"check_mobile", "param":{ "mobile":"" } }

后面的是一个二维的json

一开始我以为

JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("mobile","");
String str = jsonObject1.toString(); JSONObject jsonObject = new JSONObject();
jsonObject.put("cmd","check_mobile");
jsonObject.put("param",str);
Data = jsonObject.toString();

不可以....发现数据是这样的

然后就在想是不是   String str = jsonObject1.toString();    jsonObject.put("param",str);   不应该这样

所以

            JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("mobile","");
//String str = jsonObject1.toString(); JSONObject jsonObject = new JSONObject();
jsonObject.put("cmd","check_mobile");
jsonObject.put("param",jsonObject1);
Data = jsonObject.toString();

这样就可以了

后来尝试了其它各种方式

发现用Map也是可以的

Map map1 = new HashMap<String,String>();
map1.put("mobile",""); Map map2 = new HashMap<String,Object>();
map2.put("cmd","check_mobile");
map2.put("param",map1); String Data = new JSONObject(map2).toString();

晚安

关于Http 传输二维json的更多相关文章

  1. json 拼二维json数组

    js声明数组 以及向数组中添加as移除json数据 JavaScript声明JSON数组的方法: //部分条件,在数据渲上数据要求是数组格式而非json数组格式,取arrayJson.dataList ...

  2. ASP.NET实现二维码 ASP.Net上传文件 SQL基础语法 C# 动态创建数据库三(MySQL) Net Core 实现谷歌翻译ApI 免费版 C#发布和调试WebService ajax调用WebService实现数据库操作 C# 实体类转json数据过滤掉字段为null的字段

    ASP.NET实现二维码 using System;using System.Collections.Generic;using System.Drawing;using System.Linq;us ...

  3. jquery解析php通过ajax传过来的json二维数组对象

    ajax获得php传过来的json二维数组对象,jquery解析 php代码: <?php $news = array( '武汉'=>array(1,2,3), '广州'=>arra ...

  4. ***php解析JSON二维数组字符串(json_decode函数第二个参数True和False的区别)

    客户端的请求体中的数据:[{"msg_id": 1, "msg_status": "HAS_READ" }, { "msg_id& ...

  5. 二维数组的传输 (host <-> device)

    前言 本文的目的很明确:介绍如何将二维数组传递进显存,以及如何将二维数组从显存传递回主机端. 实现步骤 1. 在显存中为二维数组开辟空间 2. 获取该二维数组在显存中的 pitch 值 (cudaMa ...

  6. dbda封装类(包括:返回二维数组、Ajax调用返回字符串、Ajax调用返回JSON)

    <?php class DBDA { public $host = "localhost"; public $uid = "root"; public $ ...

  7. 第六篇:二维数组的传输 (host <-> device)

    前言 本文的目的很明确:介绍如何将二维数组传递进显存,以及如何将二维数组从显存传递回主机端. 实现步骤 1. 在显存中为二维数组开辟空间 2. 获取该二维数组在显存中的 pitch 值 (cudaMa ...

  8. json-lib解析json之二维JSONArray

    在接口测试中,不管是接口的请求报文还是接口的响应报文,数据全部使用json,在工作中避免不了去解析响应报文以获取某个键的值,解析josn有两种方式,一种是利用jackson,还有一种就是利用json- ...

  9. HTML-DEV-ToolLink(常用的在线字符串编解码、代码压缩、美化、JSON格式化、正则表达式、时间转换工具、二维码生成与解码等工具,支持在线搜索和Chrome插件。)

    HTML-DEV-ToolLink:https://github.com/easonjim/HTML-DEV-ToolLink 常用的在线字符串编解码.代码压缩.美化.JSON格式化.正则表达式.时间 ...

随机推荐

  1. Python 练习:简单的购物车

    salary = int(input("Please input your salary: ")) msg = ''' 1. iphone6s 5800 2. mac book 9 ...

  2. Git应用—02各种冲突场景处理(转载)

    Git冲突与解决方法 https://www.cnblogs.com/gavincoder/p/9071959.html https://www.liaoxuefeng.com/wiki/001373 ...

  3. loadrunner 场景设计-负载生成器管理

    场景设计-负载生成器管理 by:授客 QQ:1033553122 1  简介 当执行一个场景时,Controller把场景中的每个用户配到负载生成器(Load generator). 所谓的负载生成器 ...

  4. Storm的DRPC

    RPC:Remote Procedure Call DRPC:Distributed RPC Hadoop提供了RPC的实现机制,实现方法见:<>,本文主要介绍Storm的DRPC.   ...

  5. 为什么 APM 能提升 IT 团队工作质量?

    “有必要吗?”这是很多 IT 专业人员在尝试向团队内部推荐应用程序性能管理价值时所面临的问题.APM(应用程序性能管理)能为公司节约成本,提高内部工作效率,并真实了解用户对公司的系统和产品是否满意.除 ...

  6. maven(四):一个基本maven项目的pom.xml配置

    继续之前创建的test项目,一个基本项目的pom.xml文件,通常至少有三个部分 第一部分,项目坐标,信息描述等 <modelVersion>4.0.0</modelVersion& ...

  7. linux查找某段时间修改的文件的总大小

    1.统计 2017-10-25 16:30:00 至 2017-10-25 19:30:00 修改的文件的总大小 b= for i in `find -type f \( -newermt '2017 ...

  8. InnoDB中锁的模式,锁的查看,算法

    InnoDB中锁的模式   Ⅰ.总览 S行级共享锁lock in share mode X行级排它锁增删改 IS意向共享锁 IX意向排他锁 AI自增锁 Ⅱ.锁之间的兼容性 兼 X IX S IS X ...

  9. 出现error: stray ‘\357’ in program的根源

    分类: 编程语言/ C#/ 文章 这次又遇到这个这种问题,想找到它的根源.找到一个表格: The characters at a glance Here are all the printable c ...

  10. SELinux 是什么?

    一.SELinux的历史 SELinux全称是Security Enhanced Linux,由美国国家安全部(National Security Agency)领导开发的GPL项目,它拥有一个灵活而 ...