如何解析这个json
string jsonText = "{"result":"success","return":{"high":{"value":"46.50000","value_int":"4650000","display":"$46.50000","display_short":"$46.50","currency":"USD"}}}";
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(jsonText);
{
"result": "success",
"return": {
"high": {
"value": "46.50000",
"value_int": "4650000",
"display": "$46.50000",
"display_short": "$46.50",
"currency": "USD"
}
}
}
class Info{
public string value{get;set;}
public string value_int{get;set;}
public string display{get;set;}
public string display_short{get;set;}
public string currency{get;set;}
}
Dictionary<string,Dictionary<string,Info>>
public string FromJson(string json)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> jsons = (Dictionary<string, object>)serializer.DeserializeObject(json);
object value1;
object sucess;
string value1;
if (jsons.TryGetValue("result", out sucess))//第一层
{
foreach (KeyValuePair<string, object> pair in jsons)//通过KeyValuePair
{
Dictionary<string, object> jsontemple = (Dictionary<string, object>)pair.Value;//第二层
jsontemple.TryGetValue("high", out value1);
//Response.Write(value1);
}
}
else
{
result = "失败了";
}
return result;
}
public string FromJson(string json)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> jsons = (Dictionary<string, object>)serializer.DeserializeObject(json);
object value1;
object value2;
object sucess;
string result="";
if (jsons.TryGetValue("return", out sucess))
{
//Response.Write();
Dictionary<string, object> jsontemple = (Dictionary<string, object>)sucess;
jsontemple.TryGetValue("high", out value1);
foreach (KeyValuePair<string, object> pair2 in jsontemple)
{
Dictionary<string, object> jsontemple2 = (Dictionary<string, object>)pair2.Value;
jsontemple2.TryGetValue("value", out value1);
jsontemple2.TryGetValue("value_int", out value2);
Response.Write(value1+"__"+value2);
}
}
else
{
result = "";
}
return result;
}