简体   繁体   English

如何使用 Java 正则表达式提取 json 字符串中括号内的值

[英]How to extract values inside brackets in a json string using Java Regex

I would like to use regex to extract the values used inside the second []我想使用正则表达式来提取第二个 [] 中使用的值

[
"Shoes for men wither",
"Shoes for men wither leather",
]

在此处输入图像描述

I have tried the following: check all the words between quotes.我尝试了以下方法:检查引号之间的所有单词。

 Matcher m = Pattern.compile("\"([^\"]*)\"").matcher(response);

The problem with the above is that it gives me the other values outside the inner array.上面的问题是它给了我内部数组之外的其他值。

This looks like JSON, which is not a regular language , and thus can't be parsed reliably with regex.这看起来像 JSON,它不是常规语言,因此不能用正则表达式可靠地解析。 You would almost certainly be better off using a JSON parsing library, such as Gson or one of the many listed at json.org .使用 JSON 解析库(例如Gsonjson.org中列出的众多库之一)几乎肯定会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM