如题,如何简单的从一个复杂的String格式内获取某个key的值。
例如:从下面String下取到status的值。
{"response":{"info":{"code":100000},"content":{"contractinfo":{"fsdid":"14646743396","title":"邮件titty","content":"邮件内容","sendtime":"2016-05-3
1 13:59:00","donetime":"2016-05-31 14:01:09","waitnum":0,"status":"5","reason":""},"doclist":[{"docinfo":{"fid":"14646743396","filename":"contract.pdf","
pagesize":10}}],"userlist":[{"userinfo":{"name":"张三","email":"123456@qq.com","mobile":"15869000000","status":"2","signself":"","needvideo":"","signtime":
{"date":31,"hours":14,"seconds":5,"month":4,"timezoneOffset":-480,"year":116,"minutes":1,"time":1464674465000,"day":2},"is_sender":"0"}},{"userinfo":{"name":"杭州
XXXX科技有限公司","email":"123456@qq.com","mobile":"18958888888","status":"2","signself":"","needvideo":"0","signtime":{"date":31,"hours":14,"seconds":7,"
month":4,"timezoneOffset":-480,"year":116,"minutes":1,"time":1464674467000,"day":2},"is_sender":"1"}}]}}}
以上代码现在只是一个json格式的String字符串,所以我们如果传统的取里面的值,那就需要解析好几次,但是可以用一个方法就能获取到需要的值。
String status = JsonPath.read(str,"@.response.content.contractinfo.status");
参考文档 https://github.com/json-path/JsonPath 一直往下拉,很多文档,但是英文的,不过有demo应该不难模仿。