优化获取JSON字符串KEY值的方法

This commit is contained in:
seagull 2018-12-26 14:15:20 +08:00
parent e6f91fe879
commit 288cdafd7e
1 changed files with 9 additions and 6 deletions

View File

@ -146,17 +146,20 @@ public class SubString {
} }
/** /**
* 获取JSON字符串的value * 取出JSON中指定序号key的值
* @param str * @param jsonstr
* @param startstr * @param key
* @param endstr * @param indexstr 序号从1开始
* @return * @return
*/ */
public static String getJsonValue(String jsonstr, String key, String indexstr) { public static String getJsonValue(String jsonstr, String key, String indexstr) {
String result = "格式化成JSON异常"; String result = "格式化成JSON异常";
int index = 0; int index = 0;
if (isInteger(indexstr)) { if (isInteger(indexstr)&&!"0".equals(indexstr)) {
index = Integer.valueOf(indexstr); index = Integer.valueOf(indexstr)-1;
}else{
result = "指定的key值序号不是整数或是0(序号从1开始),请检查!";
return result;
} }
try { try {