I have a requirement in c# to extract the below JSON error message and read the title element. I need to remove all the characters in the string and I want only starting from errors i.e
{
"errors":
[{
"status": "404",
"title": "Not found data",
"detail": "This is a sample line of error detail."
}]
}
Please note that the exception can be anything so I just require to extract the JSON message starting from"errors".
Can you please assist me?
Code
string sb="{465F6CE7-3DF9-4BAF-8DD0-3E116CDAC9E7}0xc0c0167a0System.Net.WebException: There was no endpoint listening at http://TestData/member that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
{ "errors": [ { "status": "404", "title": "Not found data","detail": "This is a sample line of error detail." } ] }";
{.... You couldsb.IndexOf("\r\n{")orsb.IndexOf("{")to find the beggining of the json.sb.Substring(sb.IndexOf("{", 1)))- for the case posted above it will work, it obviously depends on what type of messages you'll be working with, the information you provided is not enough for a general purpose solution so you'll need to tweak it. This will skip the first character and look for the first occurence of{and take everything from that point to the end.