正则表达式从JSON字符串中提取对象 [英] Regex To Extract An Object From A JSON String

查看:329
本文介绍了正则表达式从JSON字符串中提取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有JSON字符串,我想使用正则表达式从中提取一个字段.该字段可以是ObjectArrayStringint或任何类型.我知道另一种方式,例如遍历JSON中的所有键并找到它.我想知道,是否可以使用Regex来实现.任何帮助都会很棒.

I have JSON String I would like to extract a Field from it Using Regex. The field can be an Object, Array, String, int or any type. I Know the other way like looping through all the keys in the JSON and finding it. I would like to know, This can be achieved using Regex or not. Any help would be great.

推荐答案

这可以使用或不使用正则表达式来实现

This can be achieved using Regex or not

不合理,不,因为正则表达式不太适合自行解释JSON之类的结构;与HTML一样,您需要一个适当的解析器.

Not reasonably, no, because regular expressions are not well-suited to interpreting structures like JSON on their own; as with HTML, you want a proper parser.

相反,请使用多个Java库中的任何一个来解析JSON,然后遍历其内容.在 JSON站点的底部有一个列表(我看到的是

Instead, use any of the several Java libraries for parsing the JSON and then traversing its content; there's a list of them at the bottom of the JSON site (I see Gson used a lot, but there are lots of options).

这篇关于正则表达式从JSON字符串中提取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆