日期:2014-05-17 浏览次数:20421 次
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;//第二层