0

I have converted XML into json as below for my C# code

 string xml = "<delete><id>" + id + "</id></delete>";
 string json = "{'delete': { 'id': '\' + id + \'' }}";
  • it gives me error as -

    Cannot parse provided JSON: JSON Parse Error: char=�,position=0 AFTER='�' BEFORE='���������������������������������'",

Complete Code -

string id = "Supporting Documents/SUP000008/COM-1AMLYNI01D0-0001/DeleteIssue/NGDMS_Engineering_Update.pdf";
string json = "{'delete': { 'id': '\' + id + \'' }}";
HttpContent content =  new StringContent(json, Encoding.UTF32, "application/json");
HttpResponseMessage response = await Client.Value.PostAsync(uri.OriginalString, content); // gives error

What is the correct conversion of above xml to json for C# code ?

Bokambo
  • 4,204
  • 27
  • 79
  • 130
  • 2
    JSON requires double quotes around object keys and values. Your JSON isn't valid. –  Aug 07 '19 at 20:53
  • 2
    Also, JSON decoders are required to support UTF-8. They are not required to support UTF-32, so encoding to UTF-32 might not be decodable. See: https://stackoverflow.com/questions/583562/json-character-encoding-is-utf-8-well-supported-by-browsers-or-should-i-use-nu –  Aug 07 '19 at 20:56

1 Answers1

1

Looks like you are just embedding "+ id +" into the json string, rather than the value of the variable id. Try this:

string json = "{\"delete\": { \"id\": \"" + id + "\" }}";
JonyVol
  • 366
  • 1
  • 9