Resolved Extract errors from Response Body

arun

Member
Joined
Dec 15, 2021
Messages
8
Programming Experience
5-10
hi
This is Response Body
C#:
{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "00-ab9df43aec88bf14c3f0fee89c570964-481b5dfd236414f9-00",
    "errors": {
        "CategoryName": ["Category Name is Required"],
        "CategoryId": ["Category Id is Required"]
    }
}


Can any one Help to Extract "errors" using NewtonSoft . I want a Array of Error Messages only and not the Key

Thank You
 
Solution
Since it looks like errors may contain dynamic properties try querying with Linq: Querying JSON with LINQ
C#:
var json = JObject.Parse(text);
var messages = from err in json["errors"].Values()
               from msg in err.Values()
               select msg.Value<string>();
Since it looks like errors may contain dynamic properties try querying with Linq: Querying JSON with LINQ
C#:
var json = JObject.Parse(text);
var messages = from err in json["errors"].Values()
               from msg in err.Values()
               select msg.Value<string>();
 
Solution
Back
Top Bottom