C#/Json.Net Exceptions slowing down parsing -
I use Newtonsoft.Json to parse a Jason string.
There is a lot of entries in the data I `parsing, many of which have a large load of properties optional.
The code for parsing looks like this:
Public Bull Pars (string JSONString) {JOBEYES O; Try {jResponse = Jobbject.Parse (JSONString); } Grip (JasonReader exception) {return false; } Foreach (jResponse [ParserConstants.ResultsTag] in JobJet jResult {MyObject myObject = new MyObject (); Try {myObject.Title = (string) jResult [ParserConstants.TitleTag]; } Hold {myObject.Title = String.Empty; } // It goes for 15 other elements / some people live in the catch, when the property is mandatory, // some have a deep structure such as jResult [Tag1] [Tag2] [0] [Tag 3] result. Add (C); } Return (result! = Null & amp; result; calculation & gt; 0); } All this work is fine, but parsing is very slow because many exceptions are coming to the field which do not have any value. (I think) There are 1200 exceptions when parsing all the data there
The following are the exceptions:
Newtonsoft.Json.DLL I tried something like this instead of trying:
< Code> if (jResult [TitleTag]! = Null & jResult [TitleTag] .HasValues) {myObject.Title = (string) JRSult [title tag]; } And {myObject.Title = String.Empty; } Unfortunaly this has not worked and the data can not be parsed properly.
Can anyone help me with the option to try and catch the exceptions?
I will be happy!
jobs works as idictionary & lt; String, jtoken & gt; This is a trygetvalue method: JToken token; If (jResult.TryGetValue (title tag, out of token)) {myObject.Title = (string) token; } And {myObject.Title = String.Empty; }
Comments
Post a Comment