问题描述
这样一个json字符串怎么在代码中把result那一级个去掉?(就是把字符串"result":{}去掉){"jsonrpc":"2.0","id":"10","result":{ "resultList": [{ "name": "1", "agentName": "sdfsf", "address": "Ed Spencer", "workMethod": "22", "phone": "blue", "mobilePhone": "sdfdsf", "workLicenseId": "sdfsdf", "workLicenseIssueDate": "2012-03-23", "workLicenseInvalidateDate": "2015-03-23" }, { "name": "2", "agentName": "sdfsf", "address": "Ed Spencer", "workMethod": "22", "phone": "blue", "mobilePhone": "sdfdsf", "workLicenseId": "sdfsdf", "workLicenseIssueDate": "2012-03-23", "workLicenseInvalidateDate": "2015-03-23" }, { "name": "3", "agentName": "sdfsf", "address": "Ed Spencer", "workMethod": "22", "phone": "blue", "mobilePhone": "sdfdsf", "workLicenseId": "sdfsdf", "workLicenseIssueDate": "2012-03-23", "workLicenseInvalidateDate": "2015-03-23" }]}}
解决方案
前台删还是后台删,前台就直接遍历,后台如果你没办法改变这个得到的过程拿到result的位置p1,向后查找{,用变量存t{的个数,如果又有下一个{,t++发现},就t--,如果t==0,记录位置为p2,那么就删掉从p1到p2就可以了不知道明白没有。
解决方案二:
有个想法可以试试:将这个json字符串放入一个数组中(你的这个JSON放入数组只有3个元素),遍历这个数组删掉第3个元素