0

I got the following json result from a rest api and I am using Newtonsoft.Json to deserialize it to a c# object.

    {
  "d": {
    "results": [
      {
        "Aufnr": "4000103",
        "Workdate": "/Date(1482796800000)/",
        "Beguz": "PT07H30M00S",
      }
    ]
  }
}

Aufnr and Workdate are working with String and DateTime, but I got no clue which datatype to use for Beguz

I tried TimeSpan and DateTime and got this error: Error converting value "PT07H30M00S" to type 'System.TimeSpan'. Path '[0].Beguz'

Any ideas?

Tommehh
  • 872
  • 1
  • 17
  • 44
  • 2
    Why would be String wrong? – Leo Chapiro Jan 17 '17 at 16:18
  • 2
    That is a string,isn't it? I guess that it contains a time (07:30:00) but with that format is a string. You could add a property to your object to "translate" it to datetime, or use a custom converter – Pikoh Jan 17 '17 at 16:19
  • to me this look like a timespan format. You need to parse it manually do – Jester Jan 17 '17 at 16:20
  • 2
    @J.Steen _"Nowhere near a standardized format"_ - [is ISO 8601 standardized enough](http://stackoverflow.com/questions/12466188/how-do-i-convert-an-iso8601-timespan-to-a-c-sharp-timespan)? ;) – CodeCaster Jan 17 '17 at 16:22
  • 2
    @CodeCaster Holy crap, I was looking through the ISO8601 before I posted that comment - very briefly I admit - but missed that! My extreme bad. – J. Steen Jan 17 '17 at 16:22
  • Have a look [here](https://github.com/JamesNK/Newtonsoft.Json/issues/863).You've got a example custom converter that may help you – Pikoh Jan 17 '17 at 16:30

1 Answers1

3

This is a pure string:

public string Beguz { get; set; }

Of course if you want this PT07H30M00S string to be represented by some complex custom structure you could write a custom JsonConverter to achieve this task. In this converter you will need to provide the logic of how to parse this string back to some custom structure of yours.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928