版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_33643757/article/details/84139391
Unity学习笔记002.获取Json支付某节点的值
public static string GetJsonValue(string jsonStr, string key)
{
string result = string.Empty;
if (!string.IsNullOrEmpty(jsonStr))
{
key = "\"" + key.Trim('"') + "\"";
int index = jsonStr.IndexOf(key) + key.Length + 1;
if (index > key.Length + 1)
{
//先截逗号,若是最后一个,截"}"号,取最小值
int end = jsonStr.IndexOf(',', index);
if (end == -1)
end = jsonStr.IndexOf('}', index);
result = jsonStr.Substring(index, end - index);
result = result.Trim(new[] { '"', ' ', '\"', '[', ']' }); //过滤引号或空格
}
return result;
}
}