java json字符串处理
来源:互联网 发布:淘宝上哪个螺蛳粉正宗 编辑:程序博客网 时间:2024/05/06 04:07
使用Java操作JSON字符串对象
http://www.blogjava.net/Werther/archive/2010/01/20/310262.html
Java解析Json(org.json,json-lib)
http://ysj5125094.iteye.com/blog/1633238代码样例:
// 输出结果为{"version": 4,"addr": "192.160.1.11"}private static void test1(){String s = "{\"internal_1\": [{\"version\": 4,\"addr\": \"192.160.1.11\"}]}";String regex = ".+?\\[(.+?)\\].+?";Pattern pattern = Pattern.compile(regex);Matcher matcher = pattern.matcher(s);if (matcher.matches()) {String group = matcher.group(1);System.out.println(group);}else {System.out.println("no matches!!");}}// 输出结果为{"Done":1,"ReturnType":1,"Msg":"HELLO,上海"}private static void test2(){String s="TestJsonResponse{TestJsonResult={\"Done\":1,\"ReturnType\":1,\"Msg\":\"HELLO,上海\"};}";String regex = ".+?\\=(.+?)\\;.+?";Pattern pattern = Pattern.compile(regex);Matcher matcher = pattern.matcher(s);if (matcher.matches()) {String group = matcher.group(1);System.out.println(group);}else {System.out.println("no matches!!");}}//结果为HELLO,上海private static void test3() { /*JSONObject jsonObject = new JSONObject(); try {jsonObject.put("a", 1);jsonObject.put("b", 1.1); jsonObject.put("c", 1L); jsonObject.put("d", "test"); jsonObject.put("e", true); } catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();} System.out.println(jsonObject); // 输出{"d":"test","e":true,"b":1.1,"c":1,"a":1}try {System.out.println(jsonObject.getString("d"));// 输出test} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();} */String s="{\"Done\":1,\"ReturnType\":1,\"Msg\":\"HELLO,上海\"}";try {JSONObject jsonObject2 = new JSONObject(s); System.out.println(jsonObject2.getString("Msg")); // 输出HELLO,上海} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();} }
- java 处理 json字符串
- java json字符串处理
- java处理json字符串实例
- java 处理json字符串中null值
- 处理json字符串
- JS处理JSON字符串
- js处理JSON字符串
- python处理JSON字符串
- PHP json字符串处理
- json特殊字符串处理
- Json字符串的处理
- Json字符串处理
- Hive处理JSON字符串
- JSON字符串的处理
- Js处理JSON字符串
- JSon字符串处理
- 使用json.org和json-lib来处理json字符串和java对象的转化
- java对json数组格式的字符串的处理
- java中密码修改
- 计算n!末尾所含0的个数
- 无线网桥中常用的短语含义
- 使用keil建立标准STM32工程模版(图文详细版!)
- java注册界面+mysql数据库
- java json字符串处理
- UNIX网络编程卷一 笔记 第7章 套接字选项
- android 自定义属性通过反射关联组件与方法
- 推荐ios新手学习网站
- java链接mysql数据库
- The specified child already has a parent. You must call removeView() on the child's parent first.
- SQLite Administrator 中文乱码的问题
- tp命令进行transport请求
- 软件版本怎么定义