我正在尝试反序列化实时聊天 api json 响应,以通过使用 user_type 进行过滤来访问消息 ID 和文本JSON 响应{{ "events": [ { "type": "agent_details", "message_id": 1, "timestamp": 1532396384, "user_type": "agent", "agent": { "name": "Adam Harris", "job_title": "Support Agent", "avatar": "livechat.s3.amazonaws.com/default/avatars/ab5b0666feffd67600206cd519fd77ea.jpg" } }, { "type": "message", "message_id": 3, "timestamp": 1532396387, "user_type": "visitor", "text": "hi" } ]}}JsonOject 类class JsonLiveChatEvent { public class Rootobject { public Event[] events { get; set; } } public class Event { public string type { get; set; } public int message_id { get; set; } public int timestamp { get; set; } public string user_type { get; set; } public Agent agent { get; set; } public string text { get; set; } } public class Agent { public string name { get; set; } public string job_title { get; set; } public string avatar { get; set; } } }Json转换器string jsonStr= await Api.Chat.GetPendingMessages(visitorID, licenseID, var chatEvent = JsonConvert.DeserializeObject<Rootobject>(jsonStr);例如,chatEvent 对象不会让我调用chatEvent.events.message_id。任何帮助将不胜感激,因为这是我第一次在 c# 中使用 json
- 3 回答
- 0 关注
- 305 浏览
添加回答
举报
0/150
提交
取消