如何将其反序列化为变量? C #。举个例子,已经是第二天,没有进入库JSON.NET
{"messages":[{"text":"TEXT MESSAGE","channel":"main":"from":"USERNAME","fromid":651765,"t":1379970985409,"tc":"f16d7e"}}}
所以
void timer_Tick(object sender, EventArgs e)
{
string json = @"{""messages"":[{""text"":""TEXT MESSAGE"",""channel"":""main"":""from"":""USERNAME"",""fromid"":651765,""t"":1379970985409,""tc"":""f16d7e""}}} ";
dynamic stuff = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
string color = stuff.text;
label1.Text = color;
}
解析值后,遇到意外字符::。路径'消息[0] .channel',第1行,第52位。
答案 0 :(得分:1)
我认为main和from之间的冒号必须是逗号。第二个结束卷曲应该是平方卷曲。
所以你的字符串:
@"{""messages"":[{""text"":""TEXT MESSAGE"",""channel"":""main"":""from"":""USERNAME"",""fromid"":651765,""t"":1379970985409,""tc"":""f16d7e""}}} ";
应该是这样的:
@"{""messages"":[{""text"":""TEXT MESSAGE"",""channel"":""main"",""from"":""USERNAME"",""fromid"":651765,""t"":1379970985409,""tc"":""f16d7e""}]} ";