package com.kk.test;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

/**

* @author :

* @date :Created in 2023/12/12 15:08

* @description:

* @modified By:

*/

public class jsontest {

public static void main(String[] args) {

String jsonString = "{\"name\":\"json在线编辑器\",\"biz\":{\"name\":\"123\"},\"v1.0\":\"2014-07-02 22:05 工具上线\",\"v2.0\":\"2016-11-16 14:13 增加php, go类生成\",\"v2.1\":\"2016-11-19 01:17 增加java类生成\",\"v2.2\":\"2021-03-07 10:21 增加转换yaml功能\",\"v2.3\":\"2023-11-30 00:44 修复大数精度丢失的问题\"}";

String key = "name";

Pattern pattern = Pattern.compile("\"" + key + "\":\"(.*?)\"");

Matcher matcher = pattern.matcher(jsonString);

while (matcher.find()) {

String value = matcher.group(1);

System.out.println("Value of key \"" + key + "\": " + value);

}

}

}

执行结果如下:

文章来源

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。