Json转List[Dictionary] Json格式:[[{}],[{},{},{}]]
public static List<Dictionary<string, object>> User_ParseComplexJson(string str)
{
JArray Json = JArray.Parse(str);
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
for (int i = 0; i < Json.Count; i++)
{
ArrayList arr = (ArrayList)JsonConvert.DeserializeObject(Convert.ToString(Json[i]), typeof(ArrayList));
foreach (object item in arr)
{
Dictionary<string, object> dic = (Dictionary<string, object>)JsonConvert.DeserializeObject(item.ToString(), typeof(Dictionary<string, object>));
list.Add(dic);
}
}
return list;
}
Json转List[Dictionary] Json格式:[[{}],[{},{},{}]]
public static List<Dictionary<string, object>> User_ParseJArrayJson(string str)
{
JArray Json = JArray.Parse(str);
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
for (int i = 0; i < Json.Count; i++)
{
Dictionary<string, object> dic = (Dictionary<string, object>)JsonConvert.DeserializeObject(Convert.ToString(Json[i]), typeof(Dictionary<string, object>));
list.Add(dic);
}
return list;
}
Json解析 格式为{Json:[{“Key”:“Value”}]}
public static JObject User_ParseKeyJson(string s_Json)
{
JObject Jobj = JObject.Parse(s_Json);
return Jobj;
}
Json 转 Dictionary
public static Dictionary<string, object> User_ParseJsonDict(string s_Json)
{
Dictionary<string, object> Dic = (Dictionary<string, object>)JsonConvert.DeserializeObject(s_Json, typeof(Dictionary<string, object>));
return Dic;
}
Json转List[Dictionary]
public static List<Dictionary<string, object>> User_ParseJson(string str)
{
object[] objs = (object[])JsonConvert.DeserializeObject(str, typeof(object[]));
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
foreach (object item in objs)
{
Dictionary<string, object> dic = (Dictionary<string, object>)JsonConvert.DeserializeObject(item.ToString(), typeof(Dictionary<string, object>));
list.Add(dic);
}
return list;
}
Json 转List[string]
public static List<string> User_ParseListJson(string s_Json)
{
object[] objs = (object[])JsonConvert.DeserializeObject(s_Json, typeof(object[]));
List<string> list = new List<string>();
foreach (object item in objs)
{
string str = (string)JsonConvert.DeserializeObject(item.ToString(), typeof(string));
list.Add(str);
}
return list;
}
Json转DataSet
public static DataSet JsonToDataSet(string Json)
{
try
{
return JsonConvert.DeserializeObject<DataSet>(Json);
}
catch
{
return null;
}
}