Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert from JSon to Object Collection

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...

like image 938
Riz Avatar asked Oct 25 '22 17:10

Riz


1 Answers

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"
    }
]
like image 170
Jakub Konecki Avatar answered Oct 27 '22 09:10

Jakub Konecki