Link to home
Start Free TrialLog in
Avatar of Dinesh Kumar
Dinesh KumarFlag for India

asked on

parse Json in C#

Hi Experts,

In the OData Service, I am returning this way
return JsonConvert.SerializeObject(List<Data> type)
here return type is the String;

The output is as follows:

string message="{\r\n  \"@odata.context\":\"http://localhost:6717/ff-service/$metadata#Edm.String\",\"value\":\"[{\\\"Id\\\":\\\"BPOXE\\\",\\\"TotalAmount\\\":-13.5588},{\\\"Id\\\":\\\"PDXXX\\\",\\\"TotalAmount\\\":0.0}]\"\r\n}";

Open in new window


not sure why there is \\\ symbols.

the question is How can I parse it using  a class JsonConvert existing in Newtonsoft.Json

it should be equal to List<Data>
where Data consists of two fields Id and TotalAmount.

Can I use the following class to parse the above json response(if possible)

    public class ODataResponse<T>
    {
        [JsonProperty("odata.metadata")]
        public string Metadata { get; set; }
        public List<T> Value { get; set; }

    }

Open in new window

Avatar of Jeevan Bordoloi
Jeevan Bordoloi
Flag of India image

Try
JsonConvert.DeserializeObject<List<Data>>(yourSerializedString;

Open in new window

.
Avatar of Dinesh Kumar

ASKER

it did not work.
ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Louisfr