0

如何将其反序列化为变量?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;


        }

解析值后遇到意外字符::. 路径'messages[0].channel',第 1 行,位置 52。

4

1 回答 1

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""}]} ";
于 2013-09-25T18:44:38.667 回答