json解析

public static string GetJosnValue(string json, string key)
{
string result = string.Empty;
if (!string.IsNullOrEmpty(json))
{
key = "\"" + key.Trim('"') + "\"";
int index = json.IndexOf(key) + key.Length + 1;
if (index > key.Length + 1)
{
//先截逗号,若是最后一个,截“}”号,取最小值

int end = json.IndexOf(',', index);
if (end == -1)
{
end = json.IndexOf('}', index);
}
//index = json.IndexOf('"', index + key.Length + 1) + 1;
result = json.Substring(index, end - index);
//过滤引号或空格
result = result.Trim(new char[] { '"', ' ', '\'' });
}
}
return result;
}

posted @ 2013-01-24 13:41  王者杂货铺  阅读(194)  评论(0编辑  收藏  举报