使用JSON.NET
现在list中的内容不同,在类中定义所有变量,但yescon等为nothing,解析失败,请指点class a
{
string result
string msg
string level
b list
}class b
{
uin
name
level
value
pos
fight
sex
yescon
darenflag
lwcon
}以下为JSON数据:
{
"result": "0",
"msg": "",
"level": "7",
"list": [
{
"uin": "10",
"name": "羊魔王",
"level": "25",
"value": "0",
"pos": "10",
"fight": "1",
"tips": "羊魔王,传说中的乐斗BOSS,与其好感度到达一定值,可以获得帮派技能。",
"dec": "看似很威风凛凛的羊魔王,其实拥有温纯的心,一直暗恋月璇姐姐,可惜别人已心有所属。"
},
{
"uin": "2",
"name": "乐斗教主",
"level": "40",
"value": "0",
"pos": "10",
"fight": "1",
"tips": "乐斗教主,传说中的乐斗BOSS,与其好感度到达一定值,可以获得帮派技能。",
"dec": "乐斗神教教主,前武林盟主,自退位后一直致力培养新人,想通过子弟在江湖中占一席位。"
},
{
"uin": "123456",
"name": "AAA",
"level": "1",
"value": "1",
"pos": "1",
"fight": "2",
"sex": "0",
"yescon": "0",
"darenflag": "0",
"lwcon": "0"
},
{
"uin": "654321",
"name": "BBB",
"level": "2",
"value": "329211",
"pos": "2",
"fight": "1",
"sex": "1",
"yescon": "0",
"darenflag": "0",
"lwcon": "0"
}
]
}
现在list中的内容不同,在类中定义所有变量,但yescon等为nothing,解析失败,请指点class a
{
string result
string msg
string level
b list
}class b
{
uin
name
level
value
pos
fight
sex
yescon
darenflag
lwcon
}以下为JSON数据:
{
"result": "0",
"msg": "",
"level": "7",
"list": [
{
"uin": "10",
"name": "羊魔王",
"level": "25",
"value": "0",
"pos": "10",
"fight": "1",
"tips": "羊魔王,传说中的乐斗BOSS,与其好感度到达一定值,可以获得帮派技能。",
"dec": "看似很威风凛凛的羊魔王,其实拥有温纯的心,一直暗恋月璇姐姐,可惜别人已心有所属。"
},
{
"uin": "2",
"name": "乐斗教主",
"level": "40",
"value": "0",
"pos": "10",
"fight": "1",
"tips": "乐斗教主,传说中的乐斗BOSS,与其好感度到达一定值,可以获得帮派技能。",
"dec": "乐斗神教教主,前武林盟主,自退位后一直致力培养新人,想通过子弟在江湖中占一席位。"
},
{
"uin": "123456",
"name": "AAA",
"level": "1",
"value": "1",
"pos": "1",
"fight": "2",
"sex": "0",
"yescon": "0",
"darenflag": "0",
"lwcon": "0"
},
{
"uin": "654321",
"name": "BBB",
"level": "2",
"value": "329211",
"pos": "2",
"fight": "1",
"sex": "1",
"yescon": "0",
"darenflag": "0",
"lwcon": "0"
}
]
}
{
public string result;
public string msg;
public string level;
public B[] list;
}
class B
{
public string uin;
public string name;
public string level;
public string value;
public string pos;
public string fight; public string tips;
public string dec; public string sex;
public string yescon;
public string darenflag;
public string lwcon;
}
A value = fastCSharp.setup.cSharp.ajax.parseJson.Get<A>(jsonString);
但引用它的EXE编译失败,没有任何提示,取消引用就编译成功
JSON.NET这种情况无能为力吗?!
//成功运行,你感受一下。
class Program
{
static void Main(string[] args)
{
String json = @"{
""result"": ""0"",
""msg"": """",
""level"": ""7"",
""list"": [
{
""uin"": ""10"",
""name"": ""羊魔王"",
""level"": ""25"",
""value"": ""0"",
""pos"": ""10"",
""fight"": ""1"",
""tips"": ""羊魔王,传说中的乐斗BOSS,与其好感度到达一定值,可以获得帮派技能。"",
""dec"": ""看似很威风凛凛的羊魔王,其实拥有温纯的心,一直暗恋月璇姐姐,可惜别人已心有所属。""
},
{
""uin"": ""2"",
""name"": ""乐斗教主"",
""level"": ""40"",
""value"": ""0"",
""pos"": ""10"",
""fight"": ""1"",
""tips"": ""乐斗教主,传说中的乐斗BOSS,与其好感度到达一定值,可以获得帮派技能。"",
""dec"": ""乐斗神教教主,前武林盟主,自退位后一直致力培养新人,想通过子弟在江湖中占一席位。""
},
{
""uin"": ""123456"",
""name"": ""AAA"",
""level"": ""1"",
""value"": ""1"",
""pos"": ""1"",
""fight"": ""2"",
""sex"": ""0"",
""yescon"": ""0"",
""darenflag"": ""0"",
""lwcon"": ""0""
},
{
""uin"": ""654321"",
""name"": ""BBB"",
""level"": ""2"",
""value"": ""329211"",
""pos"": ""2"",
""fight"": ""1"",
""sex"": ""1"",
""yescon"": ""0"",
""darenflag"": ""0"",
""lwcon"": ""0""
}
]
}"; A a = Newtonsoft.Json.JsonConvert.DeserializeObject<A>(json); Console.ReadKey();
}
}
class A
{
public String Result { get; set; }
public String Msg { get; set; }
public String Level { get; set; }
[Newtonsoft.Json.JsonProperty(PropertyName="list")]
public List<B> B { get; set; }
}
class B
{
public String Uin { get; set; }
public String Name { get; set; }
public String Level { get; set; }
public String Value { get; set; }
public String Pos { get; set; }
public String Fight { get; set; }
public String Sex { get; set; }
public String Yescon { get; set; }
public String Darenflag { get; set; }
public String Lwcon { get; set; }
}