如何从JSON字符串中提取特定字段的值 - Java示例
{"Result":{"ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":668038,"Number":"BS63","DIndex":0}],"SuccessMessages":[],"MsgCode":0},"Id":668038,"Number":"BS63","NeedReturnData":[{}]}}这一串字符串怎么用Java获取到中间的true内容:要获取中间的true,可以使用Java中的字符串处理方法进行截取和提取。\n\njava\nString jsonString = "{\"Result\":{\"ResponseStatus\":{\"IsSuccess\":true,\"Errors\":[ ],\"SuccessEntitys\":[ {\"Id\":668038,\"Number\":\"BS63\",\"DIndex\":0}],\"SuccessMessages\":[ ],\"MsgCode\":0},\"Id\":668038,\"Number\":\"BS63\",\"NeedReturnData\":[ ]}}";\nint startIndex = jsonString.indexOf("\"IsSuccess\":") + "\"IsSuccess\":".length();\nint endIndex = jsonString.indexOf(",\"Errors\");\nString isSuccessString = jsonString.substring(startIndex, endIndex);\nboolean isSuccess = Boolean.parseBoolean(isSuccessString);\nSystem.out.println(isSuccess);\n\n\n输出结果为true。
原文地址: https://www.cveoy.top/t/topic/pwB4 著作权归作者所有。请勿转载和采集!