从 JSon 转换为对象集合

发布于 2024-10-22 05:07:22 字数 1336 浏览 3 评论 0原文

下面是我的 json 字符串,我试图将其解析为我

正在使用的类的列表 NewtonsJson.net.3.5

[
    {
        "message": {
            "$": "@12:55 Big Rally on South Bound of Dr. B.A. Road. Motorists may use RAK Road, P. D'Melow Road & A.B. Road for CST.\n -visit icicilombard.com"
        },
        "picture": {
            "$": ""
        },
        "medium": {
            "$": "API"
        },
        "timestamp": {
            "$": "03\/15\/2011 12:55:42 IST"
        }
    }
]

这是我的类,我希望将我的 json 解析为

public class GupShupTrafficAlerts
    {
        private string _message = string.Empty;

        private string _picture = string.Empty;

        private string _medium = string.Empty;

        private string _timeStamp = string.Empty;

        public String message
        {
            get;
            set;
        }

        public string timestamp
        {
            get;
            set;
        }

        public string medium
        {
            get;
            set;
        }

        public string picture
        {
            get;
            set;
        }
    }

这是我尝试解析列表的方式,

List<GupShupTrafficAlerts> lstTrafficAlert = 
JsonConvert.DeserializeObject<List<GupShupTrafficAlerts>>(@JSonString);

但是无济于事 请帮我...

Below is my json string, which i am trying to parse to list of my class

i am using NewtonsJson.net.3.5

[
    {
        "message": {
            "$": "@12:55 Big Rally on South Bound of Dr. B.A. Road. Motorists may use RAK Road, P. D'Melow Road & A.B. Road for CST.\n -visit icicilombard.com"
        },
        "picture": {
            "$": ""
        },
        "medium": {
            "$": "API"
        },
        "timestamp": {
            "$": "03\/15\/2011 12:55:42 IST"
        }
    }
]

This is my class of which i want my json to be parsed to

public class GupShupTrafficAlerts
    {
        private string _message = string.Empty;

        private string _picture = string.Empty;

        private string _medium = string.Empty;

        private string _timeStamp = string.Empty;

        public String message
        {
            get;
            set;
        }

        public string timestamp
        {
            get;
            set;
        }

        public string medium
        {
            get;
            set;
        }

        public string picture
        {
            get;
            set;
        }
    }

this is the way i m trying to parse to List

List<GupShupTrafficAlerts> lstTrafficAlert = 
JsonConvert.DeserializeObject<List<GupShupTrafficAlerts>>(@JSonString);

but to no avail
Please help me...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性 2024-10-29 05:07:22

您的 JSON 应该如下所示:

[
    {
        "message": "@12:55 Big Rally on South Bound of Dr. B.A. Road. Motorists may use RAK Road, P. D'Melow Road & A.B. Road for CST.\n -visit icicilombard.com",
        "picture": "",
        "medium": "API",
        "timestamp":"03\/15\/2011 12:55:42 IST"
    }
]

Your JSON should look like that:

[
    {
        "message": "@12:55 Big Rally on South Bound of Dr. B.A. Road. Motorists may use RAK Road, P. D'Melow Road & A.B. Road for CST.\n -visit icicilombard.com",
        "picture": "",
        "medium": "API",
        "timestamp":"03\/15\/2011 12:55:42 IST"
    }
]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文