public class SplitJson {

public static void main(String[] args) {
        // TODO Auto-generated method stub
     String str = "[{\"version\":\"100\"},{\"type\":\"210\"},{\"chanl_no\":\"30\"},{\"chanl_sub_no\":\"3001\"},{\"chanl_date\":\"\"},{\"chanl_time\":\"\"},{\"ectip_date\":\"\"},{\"chanl_flow_no\":\"\"},{\"ectip_flow_no\":\"\"},{\"chanl_trad_no\":\"3FC012\"},{\"term_inf\":\"\"},{\"resp_code\":\"\"},{\"resp_msg\":\"\"},{\"page\":\"\"},{\"maxrow\":\"\"},{\"locstr\":\"\"},{\"tot_rec\":\"\"},{\"ARRAY_3FC012\":\"\"},{\"0\":\"\"},{\"age\":\"23\"},{\"name\":\"小cn\"},{\"sex\":\"男\"},{\"1\":\"\"},{\"sex\":\"女\"},{\"age\":\"24\"},{\"name\":\"小王\"},{\"29\":\"\"},{\"name\":\"小张\"},{\"age\":\"22\"},{\"sex\":\"男\"}]";
     //正则表达式的串为{\"29\":\"\"}
     String[] splitStr = str.split("\\{\\\"\\d{1,2}\\\":\\\"\\\"\\}");
     String resultStr = splitStr[0];
     for(int i = 1; i < splitStr.length; i++){
         resultStr += splitStr[i].replaceAll("\\},\\{", ",").substring(1);//去掉多余逗号
     }
     System.out.println(str);
     System.out.println(resultStr);
     //测试空指针异常
     System.out.println(spitJson(null, null));
     System.out.println(spitJson("", null));
     System.out.println(spitJson("", ""));
    }
    
    public static String spitJson(String jsonStr, String regex){
        if(jsonStr == null || regex == null ) return "";
        String[] splitStr = jsonStr.split(regex);
        String resultStr = splitStr[0];
        
        return resultStr;
    }

}

解析json串,利用正则表达式,split的更多相关文章

  1. 怎么解析json串在.net中

    以前知道一种解析json串的方法,觉得有点麻烦.就从别的地方搜到了另一种 string json = vlt.getlist(); JObject jo = JObject.Parse(json); ...

  2. 在.net中怎么解析json串 [Error reading JObject from JsonReader. Current JsonReader item is not an obj]

    编辑时间:2017-05-10,增加一种转化list的方法 一.以前知道一种解析json串的方法,觉得有点麻烦.就从别的地方搜到了另一种 string json = vlt.getlist(); JO ...

  3. C++ 解析json串

    首先, C++ 解析json串,需要用到第三方库(json_vc71_libmtd.lib).然后,VS2010,创建项目json_read,配置项目属性.最后,拷贝下面的代码就可以看到效果了. #i ...

  4. SpringMVC Jackson 库解析 json 串属性名大小写自动转换问题

    问题描述 在项目开发中,当实体类和表中定义的某个字段为 RMBPrice,首字母是大写的,sql 查询出来的列名也是大写的 RMBPrice,但是使用 jquery 的 ajax 返回请求响应时却出错 ...

  5. java解析json串获取key和value

    网上例子巨多,纯属个人笔记: JSONObject maleArray = maleObject.getJSONObject("extension"); Iterator<S ...

  6. JavaScript中使用eval()方法解析json串

    最近在js用到了eval()方法,在这里做个笔记 当时是这么用的:data = eval("("+data+")"); data为后台向前台传送的一个json串 ...

  7. ANDROID_MARS学习笔记_S02_013_Gson解析json串

    1.MainActivity.java package com.json; import java.io.IOException; import java.io.StringReader; impor ...

  8. 使用jackson解析json串得到树模型,然后遍历树模型获得需要的数据

    Problem:从网址 http://quotes.money.163.com/hs/service/marketradar_ajax.php?host=http%3A%2F%2Fquotes.mon ...

  9. iOS 解析json串

    NSString *json = @"[{\"name\":\"a1\",\"items\":[{\"x1\" ...

随机推荐

  1. php 读取json数据文本所遇到的问题

    json数据属于特殊的字符串,一般自己写的json数据不要误加空格,回车,换行, 若是从其他文件读取过来的json数据很有可能带有空格,回车,换行等符号,导致使用json_decode()转诚数组失败 ...

  2. 查询和删除表中重复数据sql语句

      1.查询表中重复数据.select * from peoplewhere peopleId in (select   peopleId   from   people   group   by   ...

  3. lua 学习 (一 )Mac搭建lua环境和ide

    今天开始学习lua  首先是搭建环境 和 我的hello world 首先 交代一下我用的是 Mac 系统 所以在Mac上安装lua 环境很方便的 lua  Mointain Lion - Lua 5 ...

  4. Highcharts使用教程(2):设置选项

    Highcharts使用教程(2):设置选项 使用教程 | 作者:走猫步的鱼 | 2013-12-11 09:33:25 | 阅读 16次 评论 1 概述:JavaScript图表工具Highchar ...

  5. openlayer3 获取feature

    feature是放在vector的source中,所以在获取feature前,需先vector.getSource(),再去getFeature().

  6. Selenium Chrome浏览器的启动以及proxy设置

    Selenium Chrome浏览器的启动以及proxy设置   虽然WebDriver对Firefox的支持最好,之前写的脚本也都在Firefox浏览器运行,但最近项目做了整合,发现新整合的功能不太 ...

  7. iOS设计规范整理|汇总

    来源 UI中国

  8. 基于opencv和mfc的摄像头采集代码(GOMFCTemplate2)

            编写带界面的图像处理程序,选择opencv+mfc是一种很好的选择:在读取摄像头数据方面,网上的方法很多,其中shiqiyu的camerads的方法是较好的.       基于现有资料 ...

  9. 复旦高等代数 I(16级)思考题

    思考题的说明 一.本学期高代I的思考题面向16级的同学,将不定期地进行更新; 二.欢迎16级的同学通过微信或书面方式提供解答图片或纸质文件给我,优秀的解答可以分享给大家: 三.请大家先独立解答思考题, ...

  10. 2.用vs2015创建Dotnet Core的mvc项目

    如果你正确安装DotNetCore.1.0.1-VS2015Tools.Preview2.0.2,将会看到 就是第二个选项 ASP.NET Core Web Application 选择第三个,第一次 ...