码迷,mamicode.com
首页 > 编程语言 > 详细

关于用java语言解析json字符串,获取相关字段。

时间:2019-11-21 12:01:21      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:efs   没有   申请   from   name   get   osi   card   service   

string json={"请求地址:":"http://218.4.136.115:9999/TPFrameM/rest/mobilecertservice/bindusercert","请求参数:":{"head{"timestamp":1574297981146,"token":"A3205820001@kArXrdlJpdhSm_koadbCRefeBcg=@MTU3NDI5ODI4MQ=="},"params":{"devicenum":"3c4027c1f8e43be9d70e58a81f4888ff","unitorgnum":"11111118-1","enccert":"MIICBzCCAXKgAwIBAgIDAcmoMAsGCSqGSIb3DQEBBTAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOQ0NJVCBTVUJDQSBSU0EwHhcNMTkwMTI1MDYwMDU1WhcNMTkxMjI1MDYwMDU1WjAgMQswCQYDVQQGEwJDTjERMA8GA1UEAwwIY3BjZXNoaTMwgZ0wCwYJKoZIhvcNAQEBA4GNADCBiQKBgQDI+ydFwY5sK0OrDdWsh/cSDbUPkse3esx3GK+0mBOlT2DUPcK5Y556WYWRLLVMAjCn+sjWaOPxeflzhZOxy4u/yGX1/sypA46dQIN0aD1jei0S0hY3gVJrPfrx3zodUNsPb6dqVAnwmQCnQKSp2lcgH1yxcWjQz3p39tGXwOMhPwIDAQABo08wTTAfBgNVHSMEGDAWgBQYGFNuXDC5rQKfOVjF6EoILc2nIDALBgNVHQ8EBAMCBDAwHQYDVR0OBBYEFKrUXUW7PMsjZ/CCXWaa0g19GFnsMAsGCSqGSIb3DQEBBQOBgQDLDVJCDbemhAnuDw9xCXR96lwBbS1rlXSUGUtDTDlSx0r9FNWRqI+2/FOymmixQffrJxc/Yq/BVjs+bOYp5zbP1vlFgKZLeSGw+iflcjK9h0z6bjVVQSv0M+6RohF3MT4MvxCQ4b33eNSXJghcxetxKR5n6POgQ51yVTLV0DT4kA==","signcert":"MIICizCCAfagAwIBAgIDAcmnMAsGCSqGSIb3DQEBBTAmMQswCQYDVQQGEwJDTjEXMBUGA1UEAwwOQ0NJVCBTVUJDQSBSU0EwHhcNMTkwMTI1MDYwMDU1WhcNMTkxMjI1MDYwMDU1WjAgMQswCQYDVQQGEwJDTjERMA8GA1UEAwwIY3BjZXNoaTMwggEgMAsGCSqGSIb3DQEBAQOCAQ8AMIIBCgKCAQEAvKYwCoX1H2u4XnoQLlVJMcxD3vgj6y29VcjsRwLWtjfglE1tOPfjhOY0XzGSq/o9js5BaaJ86+BB0c+SGXr8CPyz+Xvw0q0VPM1k89QlA8AZKwgRqrewCzgQcIjWXmjcQTi+/KA2MWCj79spSh5RrG9bxOUEgu+rlZIVl9G0c8E412Iq6STxQhUI3BRSkiC8OjhyvmjbiEFSeybyrLCSZl25IlJ2sXy1O0ph+v2OrZqsbsNgStm1UzBPCCQHhpJpK6+5bYdEOBrIexBAmlJHO8S/Vhv/I8Xj/G7nu/xdIHWQSJwVdff1os4GGSfbwpYDljX9WyikIuWWOoymTbmm9QIDAQABo08wTTAfBgNVHSMEGDAWgBQYGFNuXDC5rQKfOVjF6EoILc2nIDALBgNVHQ8EBAMCBsAwHQYDVR0OBBYEFDec42nFEyxcHetNci3RwwL71DYEMAsGCSqGSIb3DQEBBQOBgQCaobse+1LYH+AvLzQ+EaJwRFeagKojt0xTk5hErK0XfBhFLo3DYkaffOIvZutzZOUMbj1JegCo7HKRRoulrQuV5cizGu9dpYZHiVLoSiEWev0yxoruoxCGvlUsn4ZworI3Pd4KINvnmwxxw0QtzJVeYYAQoAAaKORfQJc7ZCpK3w==","idcard":"320723199504111045","displayname":"123","mobile":"18012895810","usertype":"2","dognum":"01c9a7","admindanweiname":"cpceshi3","token":"A3205820001@kArXrdlJpdhSm_koadbCRefeBcg=@MTU3NDI5ODI4MQ==","adminmobile":""}},"返回值:":{"custom":"","status":{"code":"0","text":"管理员授权证书申请失败,的证书对应的单位名称cpceshi3与交易系统不一致"}}}

首先在该字符串两侧加上"[]":json = "[" + json + "]";

JSONArray jsonArray = JSONArray.fromObject(json);//转化为json数组。该方法必须以“[”开头,"]"结尾。

jsonArray.getJSONObject(0);//获取索引为0json数组相当于集合中的第一个。getJSONObject()方法用来获取内部还包含子字段json数组。

jsonArray.getJSONObject(0).getJSONObject("返回值:").getJSONObject("status").get("text").toString();//当没有子字段时调用get(key)方法获取字段对应的属性。

关于用java语言解析json字符串,获取相关字段。

标签:efs   没有   申请   from   name   get   osi   card   service   

原文地址:https://www.cnblogs.com/czhj/p/11904247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!