来写写json的解析吧
首先添加web引用
System.Web.Extensions
路径
c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.dll
接下来就是两个函数了,一个是根据key来获取,一个是根据index来获取
public static bool GetValue(string json, string key, out string value)
{
//解析失败的默认返回值
value = "";
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
Dictionary<string, object> obj_json = serializer.DeserializeObject(json) as Dictionary<string, object>;
if (obj_json.ContainsKey(key))
{
value = serializer.Serialize(obj_json[key]);
return true;
}
return false;
}
catch (Exception)
{
return false;
}
}
public static bool GetValue(string json, int index, out string value)
{
//解析失败的默认返回值
value =