62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
//LitJson下载地址:http://dl.oschina.net/soft/litjson
using LitJson;
namespace ConsoleApplicationTest
{
/// <summary>
/// json序列化的实体类
/// </summary>
class Info
{
public string feePrefix { get; set; }
public string areaCode { get; set; }
public int type { get; set; }
public string areaName { get; set; }
public List<string> infoFeeRateSections { get; set; }
public double fee { get; set; }
public int period { get; set; }
public int lockType { get; set; }
public double ivrFee { get; set; }
public int ivrPeriod { get; set; }
}
class Program
{
static void Main(string[] args)
{
string jsonStr = "{\"retCode\":0,\"infoFeeRates\":[{\"feePrefix\":\"\",\"areaCode\":\"09\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[\"sect1\",\"sect2\"],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"08\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"07\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"06\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"05\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"04\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"03\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"02\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"01\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"9\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"8\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"7\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"6\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"5\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"4\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"3\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"2\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6},{\"feePrefix\":\"\",\"areaCode\":\"1\",\"type\":4,\"areaName\":\"\",\"infoFeeRateSections\":[],\"fee\":0.0030,\"period\":6,\"lockType\":0,\"ivrFee\":0.0030,\"ivrPeriod\":6}]}";
JsonData jsonData = JsonMapper.ToObject(jsonStr);
if ("0".Equals(Convert.ToString(jsonData["retCode"])))//根据你的情况判断
{
//Console.WriteLine(jsonData["infoFeeRates"][0]["areaCode"]);//其实在这里可以直接取数据了 现在取得是第一个的areaCode
List<Info> list = JsonMapper.ToObject<List<Info>>(jsonData["infoFeeRates"].ToJson());//在这里把之前反序列出来的数组再tostrng掉,然后又序列化成List 两次反序列化之后效率肯定没有上面的直接取数组的值来的高
}
Console.ReadKey();
}
}
}