C#解析json数据
数据格式是这个样子的,我用的JavaScriptSerializer,但是我不懂这个对象要怎么建立,因为里面还有数组,我这样写了好像不对,谢谢大神们啊//json对象pu...
数据格式是这个样子的,我用的JavaScriptSerializer,但是我不懂这个对象要怎么建立,因为里面还有数组,我这样写了好像不对,谢谢大神们啊
//json对象
public class jsonData
{
public priceData buyOrder;
public priceData sellOrder;
public tradeData trade;
}
public class priceData
{
public string price { get; set; }
public string amount { get; set; }
}
public class tradeData
{
public string price { get; set; }
public string volume { get; set; }
public string time { get; set; }
public string type { get; set; }
}
//json数据格式
{"buyOrder":[{"price":"4372.000000","amount":"0.737391"},{"price":"4370.000000","amount":"0.340686"}],"sellOrder":[{"price":"4372.500000","amount":"0.589376"},{"price":"4387.800000","amount":"0.425231"}],"trade":[{"price":"4372.500000","volume":"0.246803","time":"2014-01-02 15:02:20","type":"2"},{"price":"4388.000000","volume":"0.000505","time":"2014-01-02 14:56:17","type":"1"}]} 展开
//json对象
public class jsonData
{
public priceData buyOrder;
public priceData sellOrder;
public tradeData trade;
}
public class priceData
{
public string price { get; set; }
public string amount { get; set; }
}
public class tradeData
{
public string price { get; set; }
public string volume { get; set; }
public string time { get; set; }
public string type { get; set; }
}
//json数据格式
{"buyOrder":[{"price":"4372.000000","amount":"0.737391"},{"price":"4370.000000","amount":"0.340686"}],"sellOrder":[{"price":"4372.500000","amount":"0.589376"},{"price":"4387.800000","amount":"0.425231"}],"trade":[{"price":"4372.500000","volume":"0.246803","time":"2014-01-02 15:02:20","type":"2"},{"price":"4388.000000","volume":"0.000505","time":"2014-01-02 14:56:17","type":"1"}]} 展开
3个回答
展开全部
你好,如果你要是解析这个JSON字符串的话,jsonData类应该这样建:
public class jsonData
{
public List<priceData> buyOrder;
public List<priceData> sellOrder;
public List<tradeData> trade;
}
解析过程:
public static void Main(string[] args)
{
var json = @"{'buyOrder':[{'price':'4372.000000','amount':'0.737391'},{'price':'4370.000000','amount':'0.340686'}],'sellOrder':[{'price':'4372.500000','amount':'0.589376'},{'price':'4387.800000','amount':'0.425231'}],'trade':[{'price':'4372.500000','volume':'0.246803','time':'2014-01-02 15:02:20','type':'2'},{'price':'4388.000000','volume':'0.000505','time':'2014-01-02 14:56:17','type':'1'}]}";
var data = ScriptDeserialize(json);
}
public static jsonData ScriptDeserialize(string strJson)
{
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Deserialize<jsonData>(strJson);
}
展开全部
你是要把已经有的json数据,转换成实体类?
还是要把实体类,转换成json数据?
using System.Web.Script.Serialization;
你要引用这个命名空间
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是要把json数据以列表的形式显示出来吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询