Skip to main content
removed langauge tag from the title
Link
t3chb0t
  • 44.7k
  • 9
  • 84
  • 190

Convert Json response to object array C#

Source Link

Convert Json response to object array C#

I'm looking for the best solution.

Here is a response from server and i need to get Organizations list:

Content-Type:application/json;charset=UTF-8
 {
   "code": 0,
   "message": "success",
   "organizations": [
     {
       "organization_id": "10234695",
       "name": "Zillum",
       "contact_name": "John Smith",
       "email": "[email protected]",
       "is_default_org": false,
       "language_code": "en",
       "fiscal_year_start_month": 0,
       "account_created_date": "2016-02-18",
       "time_zone": "PST",
       "is_org_active": true,
       "currency_id": "460000000000097",
       "currency_code": "USD",
       "currency_symbol": "$",
       "currency_format": "###,##0.00",
       "price_precision": 2
     },
     {...},
     {...}
   ]

Here is my convert method:

var contentJson = await SendRequest(request);
            var contentJo = (JObject)JsonConvert.DeserializeObject(contentJson);
            var organizationsJArray = contentJo["organizations"]
                .Value<JArray>();

            var organizations = organizationsJArray.ToObject<List<Organization>>();

Code works, but I'm looking for a better Convert Method. Can I do without converting to JArray?