Convert Newtonsoft.Json.Linq.JArray to a list of specific object type

前端 未结 6 1449
孤街浪徒
孤街浪徒 2020-11-28 18:43

I have the following variable of type {Newtonsoft.Json.Linq.JArray}.

properties[\"Value\"] {[
  {
    \"Name\": \"Username\",
    \"Selected\":         


        
6条回答
  •  醉梦人生
    2020-11-28 19:12

    The API return value in my case as shown here:

    {
      "pageIndex": 1,
      "pageSize": 10,
      "totalCount": 1,
      "totalPageCount": 1,
      "items": [
        {
          "firstName": "Stephen",
          "otherNames": "Ebichondo",
          "phoneNumber": "+254721250736",
          "gender": 0,
          "clientStatus": 0,
          "dateOfBirth": "1979-08-16T00:00:00",
          "nationalID": "21734397",
          "emailAddress": "sebichondo@gmail.com",
          "id": 1,
          "addedDate": "2018-02-02T00:00:00",
          "modifiedDate": "2018-02-02T00:00:00"
        }
      ],
      "hasPreviousPage": false,
      "hasNextPage": false
    }
    

    The conversion of the items array to list of clients was handled as shown here:

     if (responseMessage.IsSuccessStatusCode)
            {
                var responseData = responseMessage.Content.ReadAsStringAsync().Result;
                JObject result = JObject.Parse(responseData);
    
                var clientarray = result["items"].Value();
                List clients = clientarray.ToObject>();
                return View(clients);
            }
    

提交回复
热议问题