Click here to Skip to main content
15,891,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Request of json is in below format which is stored in string DATA. (below is just part of json)
...............
..............

C#
<PortfolioList>
                                            <Portfolio>
                                                <PortfolioGroup>1<\/PortfolioGroup>
                                                <WalletDeposit>0.0<\/WalletDeposit>
                                                <MediaList>
                                                    <Media>
                                                        <MediaStatus>0<\/MediaStatus>
                                                        <MediaType>0<\/MediaType>
                                                        <MediaSerial>1<\/MediaSerial>
                                                        <EncodeDateTime>2016-05-23T09:05:14.013+0200<\/EncodeDateTime>
                                                        <EncodeFiscalDate>2016-05-23<\/EncodeFiscalDate>
                                                        <ExclusiveUse>true<\/ExclusiveUse>
                                                        <MediaCodeList>
                                                            <MediaCode>
                                                                <MediaCode>1M6BYWR7XB5BXE<\/MediaCode>
                                                                <MediaCodeType>0<\/MediaCodeType>
                                                            <\/MediaCode>
                                                        <\/MediaCodeList>
                                                    <\/Media>
                                                <\/MediaList>
                                            <\/Portfolio>
                                        <\/PortfolioList>

..............
.......
..... and so on...

The problem is I am not able to read this specific format like "<portfoliolist> <\/PortfolioList> " which is coming in json request.

What I have tried:

As described in problem i have stored complete format in string DATA.

string DATA = @"{Header: {WorkstationId: " + WorkstationId +
@"}, Request: {......

System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
client.BaseAddress = new System.Uri(SnAPIUrl);
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

System.Net.Http.HttpContent content1 = new StringContent(DATA, UTF8Encoding.UTF8, "application/json");
HttpResponseMessage messge = client.PostAsync(SnAPIUrl, content1).Result;

if (messge.IsSuccessStatusCode)
{
string result = messge.Content.ReadAsStringAsync().Result;
// Error is coming here in result. (complete format is coming in varibale with error message : Unable to set json string)
//return result;
}
Posted
Comments
Richard Deeming 23-May-16 14:28pm    
The response you've shown is not JSON. It is "sort-of" XML, except that the / character is escaped.

JSON and XML are totally different things, so it's hardly surprising that you're getting an error when you try to parse an XML response as JSON.
nipen.mehta 24-May-16 0:28am    
This is request which is passing in body message in this format.
I have tried the same code and tried to parse with application/xml then also the same error is coming. (Yes I do agree with you this is sort of xml. may be the \ character is used to avoid any kind of injection because this is something related with payment. I am not sure. If in case then is there any way to ignore the \ character in each tag before i parse. just wondering)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900