Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Json DateTime Converter

$
0
0

Hi.
I have problem when showing DateTime to client from json.

I have included my code And json here :

Json.net serializer

 public Task<XList> List(string token, CancellationToken cancellationToken)
        {
            return Task.Factory.StartNew(() =>
            {
                var client = new HttpClient(_handler);

                var url = String.Format(_baseUrl + @"list/{0}", token);

                XListresult;
                using (var s = client.GetStreamAsync(url).Result)
                using (var sr = new StreamReader(s))
                using (JsonReader reader = new JsonTextReader(sr))
                {
                    var serializer = new JsonSerializer();

                    result = serializer.Deserialize<XList>(reader);
                }

                return result;

            }, cancellationToken);
        }

//******* JSON: *******//

{
  "resultCodes": "OK",
  "description": "OK",
  "totalCount": 5,
  "items": {
    "xListItem": [
      {
        "id": 169,
        "insertDate": 1411014538000,
        "amount": 100,
        "name": "name goes here",
        "localName": {
          "valueEn": "xxEn",
          "valueRu": "xxRU",
          "valueAz": "xxAz"
        },
        "type": 0,
        "categoryId": 6,
        "categoryName": "phone",
        "fields": {
          "listField": [
            {
              "id": 209,
              "listId": 169,
              "fieldId": 161,
              "value": "4586786"
            }
          ]
        },
        "comment": "comment goes her"
      }
    ]
  }
}

//******* JsonClass to beParsed *******//

namespace JsonObjects
{
    public class XList
    {
        public string resultCodes { get; set; }
        public string description { get; set; }
        public int totalCount { get; set; }
        public Items items { get; set; }
    }

    public class Items
    {
        public Xlistitem[] xListItem { get; set; }
    }

    public class Xlistitem
    {
        public int id { get; set; }
        public long insertDate { get; set; }
        public int amount { get; set; }
        public string name { get; set; }
        public Localname localName { get; set; }
        public int type { get; set; }
        public int categoryId { get; set; }
        public string categoryName { get; set; }
        public Fields fields { get; set; }
        public string comment { get; set; }
    }

    public class Localname
    {
        public string valueEn { get; set; }
        public string valueRu { get; set; }
        public string valueAz { get; set; }
    }

    public class Fields
    {
        public Listfield[] listField { get; set; }
    }

    public class Listfield
    {
        public int id { get; set; }
        public int listId { get; set; }
        public int fieldId { get; set; }
        public string value { get; set; }
    }

}

What will be your advice to convert it automatically...


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>