deserializing json object in c # with json.net , error reading/cast - c#

I'm deserializing from a json file , which has the following fields :
{ 'IdTechnician': '4', 'DescTechnician': 'Surname Name', 'LoginTechnician': 'username', 'TypeTechnician': '1', 'TelephoneTechnician': '+123456789', 'SignatureTechnician': '????\\u0000\\u0010JFIF\\u0000\\u0001\\u0002\\u0001\\u0001,\\u0001,\\u0000\\u0000??\\u0000\\u000eAdobe\\u0000d\\u0000\\u0000\\u0000\\u0000\\u0001??\\t?Exif\\u0000\\u0000MM\\u0000*\\u0000\\u0000\\u0000\\b\\u0000\\u0007\\u0001\\u0012\\u0000\\u0003\\u0000\\u0000\\u0000\\u0001\\u0000\\u0001\\u0000\\u0000\\u0001\\u001a\\u0000\\u0005\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000b\\u0001\\u001b\\u0000\\u0005\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000j\\u0001(\\u0000\\u0003\\u0000\\u0000\\u0000\\u0001\\u0000\\u0002\\u0000\\u0000\\u00011\\u0000\\u0002\\u0000\\u0000\\u0000\\u001c\\u0000\\u0000\\u0000r\\u00012\\u0000\\u0002\\u0000\\u0000\\u0000\\u0014\\u0000\\u0000\\u0000??i\\u0000\\u0004\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000?\\u0000\\u0000\\u0000?\\u0001,\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0001,\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000Adobe Photoshop CS4 Windows\\u00002011:03:09 17:10:23\\u0000\\u0000\\u0003?\\u0001\\u0000\\u0003\\u0000\\u0000\\u0000\\u0001??\\u0000\\u0000?\\u0002\\u0000\\u0004\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000??\\u0003\\u0000\\u0004\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000-\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0006\\u0001\\u0003\\u0000\\u0003\\u0000\\u0000\\u0000\\u0001\\u0000\\u0006\\u0000\\u0000\\u0001\\u001a\\u0000\\u0005\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0001\\u001c\\u0001\\u001b\\u0000\\u0005\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0001$\\u0001(\\u0000\\u0003\\u0000\\u0000\\u0000\\u0001\\u0000\\u0002\\u0000\\u0000\\u0002\\u0001\\u0000\\u0004\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0001,\\u0002\\u0002\\u0000\\u0004\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\b^\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000H\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000H\\u0000\\u0000\\u0000\\u0001????\\u0000\\u0010JFIF\\u0000\\u0001\\u0002\\u0000\\u0000H\\u0000H\\u0000\\u0000??\\u0000\\fAdobe_CM\\u0000\\u0002??\\u0000\\u000eAdobe\\u0000d?\\u0000\\u0000\\u0000\\u0001??\\u0000?\\u0000\\f\\b\\b\\b\\t\\b\\f\\t\\t\\f\\u0011\\u000b\\n\\u000b\\u0011\\u0015\\u000f\\f\\f\\u000f\\u0015\\u0018\\u0013\\u0013\\u0015\\u0013\\u0013\\u0018\\u0011\\f\\f\\f\\f\\f\\f\\u0011\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\u0001\\r\\u000b\\u000b\\r\\u000e\\r\\u0010\\u000e\\u000e\\u0010\\u0014\\u000e\\u000e\\u000e\\u0014\\u0014\\u000e\\u000e\\u000e\\u000e\\u0014\\u0011\\f\\f\\f\\f\\f\\u0011\\u0011\\f\\f\\f\\f\\f\\f\\u0011\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f??\\u0000\\u0011\\b\\u0000$\\u0000?\\u0003\\u0001\\\\u0000\\u0002\\u0011\\u0001\\u0003\\u0011\\u0001??\\u0000\\u0004\\u0000\\n??\\u0001?\\u0000\\u0000\\u0001\\u0005\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0003\\u0000\\u0001\\u0002\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\u0001\\u0000\\u0001\\u0005\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u0000\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\u0010\\u0000\\u0001\\u0004\\u0001\\u0003\\u0002\\u0004\\u0002\\u0005\\u0007\\u0006\\b\\u0005\\u0003\\f3\\u0001\\u0000\\u0002\\u0011\\u0003\\u0004!\\u00121\\u0005AQa\\u0013\\q?2\\u0006\\u0014???B#$\\u0015R?b34r??C\\u0007%?S???cs5\\u0016???&D?TdE??t6\\u0017?U?e?????u??F'???????????????Vfv????????7GWgw????????\\u0011\\u0000\\u0002\\u0002\\u0001\\u0002\\u0004\\u0004\\u0003\\u0004\\u0005\\u0006\\u0007\\u0007\\u0006\\u00055\\u0001\\u0000\\u0002\\u0011\\u0003!1\\u0012\\u0004AQaq\\\\u0013\\u00052??\\u0014??B#?R??3$b?r??CS\\u0015cs4?%\\u0006\\u0016???\\u0007&5??D?T?\\u0017dEU6te??????u??F???????????????Vfv????????'7GWgw???????\\u0000\\f\\u0003\\u0001\\u0000\\u0002\\u0011\\u0003\\u0011\\u0000?\\u0000?E[??;\\u0013\\u0006??????Z?0]?????????3?m?t?f}??/????????????:?????\\u0000K?\\u0000\\u0017_?\\u0011\\u0002?????F5.??\\u001b]L??05???<l??qq?}4???C^??\\u0000\\u0011???\\u0000?{?\\u0000??oC?e?2???+7\\r??&??[?>??z~?^?[-?}??V:??44PQ \\t&\\u0002`A\\u0012\\f??\\n?X???j\\u001c???????\\u0016???w?1??c?????n,????\\u0002\\u0012?-M??I\\u0005)$?IJU?3YM???n?sK?C#v????;k*g??V\\u001e????!?h?\\u0013?\\u0003RVN\\u0006\\u0016]????h??h????\\u0000\\u001fv;\\u0019??;\\u001a?z_???z^?!N?6Krk?\\u001a?0?\\u0016=???sN?5?-EB???\\u001a??^????\\u001d?q's??\\u001f????z*\\nRI$???I???nq\\r\\u0003?t\\t)t?+??G?E??4?\\u000b}F????,^???p?\\u0019???\\u0013\\'?\\u00034?\\u0000?s\\u0005_???=?????N??y????????\\\\?y?io?????w;??c?\\u0000?~????j?X??f??c?1???~?I?????\\u001c??,?~S???\\u0000???GcfU?fN3j????{ls???{?5?1?n???z~??}??\\u001e]??????????K^????\\u001b??????k?~E??{??P?l???\\t>?P?p?\\u0005?\\u0000??\\u0000?????\\u0000a\\u00133??\\u0002?sl??,?m/u??\\\\??????w?w?????r????r???????,]_??\\u0003?o?\\r???cY?e?~?u?Mv^5?\\u001a?j?c\\u0000?\\u0017?m?\\u00007eh???\\u0000*S??:?3?sZ?T???n\\u0000\\u001a?w?{\\u0018????????B??J?\\u0000?10?v3?w??????$??V??=??W?mX?Q???????;k=,Ue??X??f&?B?=????????F???g?[n^NmtdWS????????h?????\\u001a=OK??????}???\\u0011?hv?[?beU?Cn?\\u0010\\f?1?\\u001c?4???\\u001b??V?\\u0000c??????\\u001bE???\\u001d?\\u000688?????EsN????uXT_????vU-?O?X{\\u001df\\u0007?\\u001f??n???>?]?????=\\u001d??Tu*\\u001d??n\\u0016\\u000eP??sK??YT??k???{(k~????????\\u0003\\u001e???H\\u0010D?A???C?g???b?<????<~??,?R?????\\u0000??????\\rh\\rh\\u0010\\u0000?\\u0000\\u0013i-.??7?f?\\u0018>??Gii\\u0005??V?e\\u0014\\n??6??+?\\u0012\\u0004?=??~???Oclc?x\\u000ec?k?u\\u0004\\u001d\\u001c????D?b??k????W?V????????hs[^???c???g??\\u0000??\\u0014tS?????ev5????i\\u0004???\\u0003??m???\\\\<zQ?|?c??\\u0015????????v\\u0015\\u0015T?dd>?c?,??\\u001b\\u001d?6?[n???Z?G\\u001f?\\'??????~;???s?ln77y8?WX;??\\u001a?1?no???Uz??J?n????\\\\`\\rI<\\u0000?r???W?\\u0017d??5\\u000e\\ro??\\u00077??b?K?\\u0019?\\u0017?? ?????h,ap\\u0011?}?????????tG?ul??????-}/c\\u001c???\\u001f??\\u0014?kk~U???}??c???[?\\'??L?Z???T?\\u00167??ac\\u001cX????]??ev;??6????Q?W??>????#7WV???\\b??O??????\\u0016>???m?\\u001c?;!???????q?\\u0011?\\u001a?+??\\u0001??L????\\u001a?S?\\u0015h????X??,?e~??????h?\\u000e?????????\\u0000????Z\\u0003?\\u0015^\\r?*0[K-?????\\u0005????\\u001f??mk??????t??Z???h??k???gc\\bkv???#??]g??V?\\u000e????D???$??????$??????$?????? ??????\\'??????$??????$??????$??????$??????$?????\\u000e8Photoshop 3.0\\u00008BIM\\u0004%\\u0000\\u0000\\u0000\\u0000\\u0000\\u0010\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u00008BIM\\u0003?\\u0000\\u0000\\u0000\\u0000\\u0000\\u0010\\u0001,\\u0000\\u0000\\u0000\\u0001\\u0000\\u0002\\u0001,\\u0000\\u0000\\u0000\\u0001\\u0000\\u00028BIM\\u0004&\\u0000\\u0000\\u0000\\u0000\\u0000\\u000e\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000??\\u0000\\u00008BIM\\u0004\\r\\u0000\\u0000\\u0000\\u0000\\u0000\\u0004\\u0000\\u0000\\u0000\\u001e8BIM\\u0004\\u0019\\u0000\\u0000\\u0000\\u0000\\u0000\\u0004\\u0000\\u0000\\u0000\\u001e8BIM\\u0003?\\u0000\\u0000\\u0000\\u0000\\u0000\\t\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u00008BIM'\\u0010\\u0000\\u0000\\u0000\\u0000\\u0000\\n\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u00028BIM\\u0003?\\u0000\\u0000\\u0000\\u0000\\u0000H\\u0000/ff\\u0000\\u0001\\u0000lff\\u0000\\u0006\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u0000/ff\\u0000\\u0001\\u0000???\\u0000\\u0006\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u00002\\u0000\\u0000\\u0000\\u0001\\u0000Z\\u0000\\u0000\\u0000\\u0006\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u00005\\u0000\\u0000\\u0000\\u0001\\u0000-\\u0000\\u0000\\u0000\\u0006\\u0000\\u0000\\u0000\\u0000\\u0000\\u00018BIM\\u0003?\\u0000\\u0000\\u0000\\u0000\\u0000p\\u0000\\u0000??????????????????????\\u0003?\\u0000\\u0000\\u0000\\u0000??????????????????????\\u0003?\\u0000\\u0000\\u0000\\u0000??????????????????????\\u0003?\\u0000\\u0000\\u0000\\u0000??????????????????????\\u0003?\\u0000\\u00008BIM\\u0004\\b\\u0000\\u0000\\u0000\\u0000\\u0000\\u0010\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0002#\\u0000\\u0000\\u0002#\\u0000\\u0000\\u0000\\u00008BIM\\u0004\\u001e\\u0000\\u0000\\u0000\\u0000\\u0000\\u0004\\u0000\\u0000\\u0000\\u00008BIM\\u0004\\u001a\\u0000\\u0000\\u0000\\u0000\\u0003O\\u0000\\u0000\\u0000\\u0006\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000-\\u0000\\u0000\\u0000?\\u0000\\u0000\\u0000\\r\\u0000c\\u0000o\\u0000r\\u0000s\\u0000i\\u0000n\\u0000i\\u0000a\\u0000n\\u0000d\\u0000r\\u0000e\\u0000a\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000?\\u0000\\u0000\\u0000-\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0010\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000null\\u0000\\u0000\\u0000\\u0002\\u0000\\u0000\\u0000\\u0006boundsObjc\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000Rct1\\u0000\\u0000\\u0000\\u0004\\u0000\\u0000\\u0000\\u0000Top long\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000Leftlong\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000Btomlong\\u0000\\u0000\\u0000-\\u0000\\u0000\\u0000\\u0000Rghtlong\\u0000\\u0000\\u0000?\\u0000\\u0000\\u0000\\u0006slicesVlLs\\u0000\\u0000\\u0000\\u0001Objc\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0005slice\\u0000\\u0000\\u0000\\u0012\\u0000\\u0000\\u0000\\u0007sliceIDlong\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0007groupIDlong\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0006originenum\\u0000\\u0000\\u0000\\fESliceOrigin\\u0000\\u0000\\u0000\\rautoGenerated\\u0000\\u0000\\u0000\\u0000Typeenum\\u0000\\u0000\\u0000\\nESliceType\\u0000\\u0000\\u0000\\u0000Img \\u0000\\u0000\\u0000\\u0006boundsObjc\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000Rct1\\u0000\\u0000\\u0000\\u0004\\u0000\\u0000\\u0000\\u0000Top long\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000Leftlong\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000Btomlong\\u0000\\u0000\\u0000-\\u0000\\u0000\\u0000\\u0000Rghtlong\\u0000\\u0000\\u0000?\\u0000\\u0000\\u0000\\u0003urlTEXT\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000nullTEXT\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000MsgeTEXT\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0006altTagTEXT\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u000ecellTextIsHTMLbool\\u0001\\u0000\\u0000\\u0000\\bcellTextTEXT\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\thorzAlignenum\\u0000\\u0000\\u0000\\u000fESliceHorzAlign\\u0000\\u0000\\u0000\\u0007default\\u0000\\u0000\\u0000\\tvertAlignenum\\u0000\\u0000\\u0000\\u000fESliceVertAlign\\u0000\\u0000\\u0000\\u0007default\\u0000\\u0000\\u0000\\u000bbgColorTypeenum\\u0000\\u0000\\u0000\\u0011ESliceBGColorType\\u0000\\u0000\\u0000\\u0000None\\u0000\\u0000\\u0000\\ttopOutsetlong\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\nleftOutsetlong\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\fbottomOutsetlong\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u000brightOutsetlong\\u0000\\u0000\\u0000\\u0000\\u00008BIM\\u0004(\\u0000\\u0000\\u0000\\u0000\\u0000\\f\\u0000\\u0000\\u0000\\u0002??\\u0000\\u0000\\u0000\\u0000\\u0000\\u00008BIM\\u0004\\u0011\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u0001\\u00008BIM\\u0004\\u0014\\u0000\\u0000\\u0000\\u0000\\u0000\\u0004\\u0000\\u0000\\u0000\\u00018BIM\\u0004\\f\\u0000\\u0000\\u0000\\u0000\\bz\\u0000\\u0000\\u0000\\u0001\\u0000\\u0000\\u0000?\\u0000\\u0000\\u0000$\\u0000\\u0000\\u0001?\\u0000\\u0000C?\\u0000\\u0000\\b^\\u0000\\u0018\\u0000\\u0001????\\u0000\\u0010JFIF\\u0000\\u0001\\u0002\\u0000\\u0000H\\u0000H\\u0000\\u0000??\\u0000\\fAdobe_CM\\u0000\\u0002??\\u0000\\u000eAdobe\\u0000d?\\u0000\\u0000\\u0000\\u0001??\\u0000?\\u0000\\f\\b\\b\\b\\t\\b\\f\\t\\t\\f\\u0011\\u000b\\n\\u000b\\u0011\\u0015\\u000f\\f\\f\\u000f\\u0015\\u0018\\u0013\\u0013\\u0015\\u0013\\u0013\\u0018\\u0011\\f\\f\\f\\f\\f\\f\\u0011\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\u0001\\r\\u000b\\u000b\\r\\u000e\\r\\u0010\\u000e\\u000e\\u0010\\u0014\\u000e\\u000e\\u000e\\u0014\\u0014\\u000e\\u000e\\u000e\\u000e\\u0014\\u0011\\f\\f\\f\\f\\f\\u0011\\u0011\\f\\f\\f\\f\\f\\f\\u0011\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f\\f??\\u0000\\u0011\\b\\u0000$\\u0000?\\u0003\\u0001\\\\u0000\\u0002\\u0011\\u0001\\u0003\\u0011\\u0001??\\u0000\\u0004\\u0000\\n??\\u0001?\\u0000\\u0000\\u0001\\u0005\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0003\\u0000\\u0001\\u0002\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\u0001\\u0000\\u0001\\u0005\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u0000\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\u0010\\u0000\\u0001\\u0004\\u0001\\u0003\\u0002\\u0004\\u0002\\u0005\\u0007\\u0006\\b\\u0005\\u0003\\f3\\u0001\\u0000\\u0002\\u0011\\u0003\\u0004!\\u00121\\u0005AQa\\u0013\\'q?2\\u0006\\u0014???B#$\\u0015R?b34r??C\\u0007%?S???cs5\\u0016???&D?TdE??t6\\u0017?U?e?????u??F'???????????????Vfv????????7GWgw????????\\u0011\\u0000\\u0002\\u0002\\u0001\\u0002\\u0004\\u0004\\u0003\\u0004\\u0005\\u0006\\u0007\\u0007\\u0006\\u00055\\u0001\\u0000\\u0002\\u0011\\u0003!1\\u0012\\u0004AQaq\\\\u0013\\u00052??\\u0014??B#?R??3$b?r??CS\\u0015cs4?%\\u0006\\u0016???\\u0007&5??D?T?\\u0017dEU6te??????u??F???????????????Vfv????????'7GWgw???????\\u0000\\f\\u0003\\u0001\\u0000\\u0002\\u0011\\u0003\\u0011\\u0000?\\u0000?E[??;\\u0013\\u0006??????Z?0]?????????3?m?t?f}??/????????????:?????\\u0000K?\\u0000\\u0017_?\\u0011\\u0002?????F5.??\\u001b]L??05???<l??qq?}4???C^??\\u0000\\u0011???\\u0000?{?\\u0000??oC?e?2???+7\\r??&??[?>??z~?^?[-?}??V:??44PQ \\t&\\u0002`A\\u0012\\f??\\n?X???j\\u001c???????\\u0016???w?1??c?????n,????\\u0002\\u0012?-M??I\\u0005)$?IJU?3YM???n?sK?C#v????;k*g??V\\u001e????!?h?\\u0013?\\u0003RVN\\u0006\\u0016]????h??h????\\u0000\\u001fv;\\u0019??;\\u001a?z_???z^?!N?6Krk?\\u001a?0?\\u0016=???sN?5?-EB???\\u001a??^????\\u001d?q's??\\u001f????z*\\nRI$???I???nq\\r\\u0003?t\\t)t?+??G?E??4?\\u000b}F????,^???p?\\u0019???\\u0013\\'?\\u00034?\\u0000?s\\u0005_???=?????N??y????????\\\\?y?io?????w;??c?\\u0000?~????j?X??f??c?1???~?I?????\\u001c??,?~S???\\u0000???GcfU?fN3j????{ls???{?5?1?n???z~??}??\\u001e]??????????K^????\\u001b??????k?~E??{??P?l???\\t>?P?p?\\u0005?\\u0000??\\u0000?????\\u0000a\\u00133??\\u0002?sl??,?m/u??\\\\??????w?w?????r????r???????,]_??\\u0003?o?\\r???cY?e?~?u?Mv^5?\\u001a?j?c\\u0000?\\u0017?m?\\u00007eh???\\u0000*S??:?3?sZ?T???n\\u0000\\u001a?w?{\\u0018????????B??J?\\u0000?10?v3?w??????$??V??=??W?mX?Q???????;k=,Ue??X??f&?B?=????????F???g?[n^NmtdWS????????h?????\\u001a=OK??????}???\\u0011?hv?[?beU?Cn?\\u0010\\f?1?\\u001c?4???\\u001b??V?\\u0000c??????\\u001bE???\\u001d?\\u000688?????EsN????uXT_????vU-?O?X{\\u001df\\u0007?\\u001f??n???>?]?????=\\u001d??Tu*\\u001d??n\\u0016\\u000eP??sK??YT??k???{(k~????????\\u0003\\u001e???H\\u0010D?A???C?g???b?<????<~??,?R?????\\u0000??????\\rh\\rh\\u0010\\u0000?\\u0000\\u0013i-.??7?f?\\u0018>??Gii\\u0005??V?e\\u0014\\n??6??+?\\u0012\\u0004?=??~???Oclc?x\\u000ec?k?u\\u0004\\u001d\\u001c????D?b??k????W?V????????hs[^???c???g??\\u0000??\\u0014tS?????ev5????i\\u0004???\\u0003??m???\\\\<zQ?|?c??\\u0015????????v\\u0015\\u0015T?dd>?c?,??\\u001b\\u001d?6?[n???Z?G\\u001f?\\'??????~;???s?ln77y8?WX;??\\u001a?1?no???Uz??J?n????\\\\`\\rI<\\u0000?r???W?\\u0017d??5\\u000e\\ro??\\u00077??b?K?\\u0019?\\u0017?? ?????h,ap\\u0011?}?????????tG?ul??????-}/c\\u001c???\\u001f??\\u0014?kk~U???}??c???[?\\'??L?Z???T?\\u00167??ac\\u001cX????]??ev;??6????Q?W??>????#7WV???\\b??O??????\\u0016>???m?\\u001c?;!???????q?\\u0011?\\u001a?+??\\u0001??L????\\u001a?S?\\u0015h????X??,?e~??????h?\\u000e?????????\\u0000????Z\\u0003?\\u0015^\\r?*0[K-?????\\u0005????\\u001f??mk??????t??Z???h??k???gc\\bkv???#??]g??V?\\u000e????D???$??????$??????$?????? ??????\\'??????$??????$??????$??????$??????$???8BIM\\u0004!\\u0000\\u0000\\u0000\\u0000\\u0000U\\u0000\\u0000\\u0000\\u0001\\u0001\\u0000\\u0000\\u0000\\u000f\\u0000A\\u0000d\\u0000o\\u0000b\\u0000e\\u0000 \\u0000P\\u0000h\\u0000o\\u0000t\\u0000o\\u0000s\\u0000h\\u0000o\\u0000p\\u0000\\u0000\\u0000\\u0013\\u0000A\\u0000d\\u0000o\\u0000b\\u0000e\\u0000 \\u0000P\\u0000h\\u0000o\\u0000t\\u0000o\\u0000s\\u0000h\\u0000o\\u0000p\\u0000 \\u0000C\\u0000S\\u00004\\u0000\\u0000\\u0000\\u0001\\u00008BIM\\u0004\\u0006\\u0000\\u0000\\u0000\\u0000\\u0000\\u0007\\u0000\\b\\u0000\\u0000\\u0000\\u0001\\u0001\\u0000??\\u0010Chttp://ns.adobe.com/xap/1.0/\\u0000<?xpacket begin=\\'???\\' id=\\'W5M0MpCehiHzreSzNTczkc9d\\'?>\\r\\n<x:xmpmeta xmlns:x=\\'adobe:ns:meta/\\' x:xmptk=\\'Adobe XMP Core 4.2.2-c063 53.352624, 2008/07/30-18:12:18 \\'>\\r\\n\\t<rdf:RDF xmlns:rdf=\\'http://www.w3.org/1999/02/22-rdf-syntax-ns#\\'>\\r\\n\\t\\t<rdf:Description rdf:about=\\\\' xmlns:xmp=\\'http://ns.adobe.com/xap/1.0/\\' xmlns:dc=\\'http://purl.org/dc/elements/1.1/\\' xmlns:photoshop=\\'http://ns.adobe.com/photoshop/1.0/\\' xmlns:xmpMM=\\'http://ns.adobe.com/xap/1.0/mm/\\' xmlns:stEvt=\\'http://ns.adobe.com/xap/1.0/sType/ResourceEvent#\\' xmlns:tiff=\\'http://ns.adobe.com/tiff/1.0/\\' xmlns:exif=\\'http://ns.adobe.com/exif/1.0/\\' xmp:CreatorTool=\\'Adobe Photoshop CS4 Windows\\' xmp:CreateDate=\\'2011-03-09T17:09:27+01:00\\' xmp:ModifyDate=\\'2011-03-09T17:10:23+01:00\\' xmp:MetadataDate=\\'2011-03-09T17:10:23+01:00\\' dc:format=\\'image/jpeg\\' photoshop:ColorMode=\\'3\\' xmpMM:InstanceID=\\'xmp.iid:C525B6FA3E4AE01195AFE2861A054AE9\\' xmpMM:DocumentID=\\'xmp.did:C525B6FA3E4AE01195AFE2861A054AE9\\' xmpMM:OriginalDocumentID=\\'xmp.did:C525B6FA3E4AE01195AFE2861A054AE9\\' tiff:Orientation=\\'1\\' tiff:XResolution=\\'3000000/10000\\' tiff:YResolution=\\'3000000/10000\\' tiff:ResolutionUnit=\\'2\\' tiff:NativeDigest=\\'256,257,258,259,262,274,277,284,530,531,282,283,296,301,318,319,529,532,306,270,271,272,305,315,33432;DE7B977DF6EFF346F11FF6BE697281C5\\' exif:PixelXDimension=\\'200\\' exif:PixelYDimension=\\'45\\' exif:ColorSpace=\\'65535\\' exif:NativeDigest=\\'36864,40960,40961,37121,37122,40962,40963,37510,40964,36867,36868,33434,33437,34850,34852,34855,34856,37377,37378,37379,37380,37381,37382,37383,37384,37385,37386,37396,41483,41484,41486,41487,41488,41492,41493,41495,41728,41729,41730,41985,41986,41987,41988,41989,41990,41991,41992,41993,41994,41995,41996,42016,0,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,23,24,25,26,27,28,30;0E127CF2EACEDA719CA574253BD56212\\'>\\r\\n\\t\\t\\t<xmpMM:History>\\r\\n\\t\\t\\t\\t<rdf:Seq>\\r\\n\\t\\t\\t\\t\\t<rdf:li stEvt:action=\\'created\\' stEvt:instanceID=\\'xmp.iid:C525B6FA3E4AE01195AFE2861A054AE9\\' stEvt:when=\\'2011-03-09T17:10:23+01:00\\' stEvt:softwareAgent=\\'Adobe Photoshop CS4 Windows\\'/>\\r\\n\\t\\t\\t\\t</rdf:Seq>\\r\\n\\t\\t\\t</xmpMM:History>\\r\\n\\t\\t</rdf:Description>\\r\\n\\t</rdf:RDF>\\r\\n</x:xmpmeta>\\r\\n \\n o\\u000bP????\\u0006??T??/w?\\u0000\\u0007[???????', 'MailTechnician': 'email#email.it', 'WbsTechnician': 'xyz', 'NumberPincerTechnician': '' }
with the following code
using (StreamReader file = File.OpenText(#"path\\file.json"))
{
JsonSerializer serializer = new JsonSerializer();
tbl_tech tech = (tbl_tech)serializer.Deserialize(file, typeof(tbl_tech));
}
this is the object that i use
public partial class tbl_tech
{
public tbl_tech()
{
this.tbl_odl = new HashSet<tbl_odl>();
this.tbl_pdr = new HashSet<tbl_pdr>();
}
public long IdTechnician { get; set; }
public string DescTechnician { get; set; }
public string LoginTechnician { get; set; }
public string TelephoneTechnician { get; set; }
public string SignatureTechnician { get; set; }
public string MailTechnician { get; set; }
public string WbsTechnician { get; set; }
public string NumberPincerTechnician { get; set; }
public Nullable<long> TypeTechnician { get; set; }
public virtual ICollection<tbl_odl> tbl_odl { get; set; }
public virtual ICollection<tbl_pdr> tbl_pdr { get; set; }
}
and this is the error generate from visual studio.
{"Could not cast or convert from System.String to eStartService.tbl_tech."}
I do not understand is that the fields of the object are perfectly identical to those of my object , so where wrong assignment given to json ? I am that something wrong ? thanks

That json is an array of objects, not an object. See the [ and ] at the beginning/end?
tbl_tech[] tech = (tbl_tech[])serializer.Deserialize(sr, typeof(tbl_tech[]));

If I modify the code like this:
public partial class tbl_tech
{
public tbl_tech()
{
//this.tbl_odl = new HashSet<tbl_odl>();
//this.tbl_pdr = new HashSet<tbl_pdr>();
}
public long IdTechnician { get; set; }
public string DescTechnician { get; set; }
public string LoginTechnician { get; set; }
public string TelephoneTechnician { get; set; }
public string SignatureTechnician { get; set; }
public string MailTechnician { get; set; }
public string WbsTechnician { get; set; }
public string NumberPincerTechnician { get; set; }
public Nullable<long> TypeTechnician { get; set; }
//public virtual ICollection<tbl_odl> tbl_odl { get; set; }
//public virtual ICollection<tbl_pdr> tbl_pdr { get; set; }
}
The deserialization works fine.Becase now your json and your Type are similar.

Try using JSon2csharp when creating your JSon representation.
I removed the "'" from the numbers too:
[{'IdTechnician': 4, 'DescTechnician': 'Surname Name', 'LoginTechnician': 'name', 'TypeTechnician': 1, 'TelephoneTechnician': '+123456789', 'SignatureTechnician': 'signaturepath', 'MailTechnician': 'email#email.com', 'WbsTechnician': 'XYZ', 'NumberPincerTechnician': 1}]
Which gives the following model:
public class RootObject
{
public int IdTechnician { get; set; }
public string DescTechnician { get; set; }
public string LoginTechnician { get; set; }
public int TypeTechnician { get; set; }
public string TelephoneTechnician { get; set; }
public string SignatureTechnician { get; set; }
public string MailTechnician { get; set; }
public string WbsTechnician { get; set; }
public int NumberPincerTechnician { get; set; }
}
You can deserialize it in the following way:
IList<RootObject> result = new List<RootObject>();
using (StreamReader file = File.OpenText(#"path\\file.json"))
{
result = JsonConvert.DeserializeObject<List<RootObject>>(file.ReadToEnd());
}

Related

Cannot deserialize the current JSON in C#

I faced the problem: Cannot deserialize the current JSON object.
As follows:
public List<Track> Tracks { get; set; }
public async Task<List<Track>> GetTracking()
{
using (var httpClient = new HttpClient())
{
using (var requests = new HttpRequestMessage(new HttpMethod("GET"), "urlxxxxxxxx..."))
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
requests.Headers.TryAddWithoutValidation("accept", "application/json");
var response = await httpClient.SendAsync(requests);
using (HttpContent content = response.Content)
{
var jsonStr = content.ReadAsStringAsync().GetAwaiter().GetResult();
var res = JsonConvert.DeserializeObject<List<Track>>(jsonStr); //Get Error**
Tracks = res;
}
}
}
return Tracks;
}
Model Class
public class Track
{
public List<Events> events { get; set; }
}
public class Events
{
public string eventID { get; set; }
public string eventType { get; set; }
public string eventDateTime { get; set; }
public string eventCreatedDateTime { get; set; }
public string eventClassifierCode { get; set; }
public string transportEventTypeCode { get; set; }
public string documentID { get; set; }
public string shipmentEventTypeCode { get; set; }
public List<DocumentReferences> documentReferences { get; set; }
public TransportCall transportCall { get; set; }
}
public class DocumentReferencesMearsk
{
public string documentReferenceType { get; set; }
public string documentReferenceValue { get; set; }
}
public class TransportCallMaersk
{
public string transportCallID { get; set; }
public string carrierServiceCode { get; set; }
public string exportVoyageNumber { get; set; }
public string importVoyageNumber { get; set; }
public int transportCallSequenceNumber { get; set; }
public string UNLocationCode { get; set; }
public string facilityCode { get; set; }
public string facilityCodeListProvider { get; set; }
public string facilityTypeCode { get; set; }
public string otherFacility { get; set; }
public string modeOfTransport { get; set; }
public LocationMearsk location { get; set; }
public VesselMearsk vessel { get; set; }
}
My input data:
https://drive.google.com/file/d/12g0nHkHlmbU4Af8crHlzKXD_ERIZdCyH/view?usp=sharing
As in my description. I get the error: I get the error: Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[XX. Models.Track]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
Even though I declared: public List events { get; set; }
Is the problem I have misunderstood the format of DeserializeObject. Looking forward to everyone's help. Thank
you have an object, not an array
var res = JsonConvert.DeserializeObject<Track>(jsonStr);
and fix class
public class Events
{
....
public List<DocumentReferencesMearsk> documentReferences { get; set; }
public TransportCallMaersk transportCall { get; set; }
}
Your model is incomplete and has typos. Assuming you have the correct versions of them.
You are doing:
var res = JsonConvert.DeserializeObject<List<Track>>(jsonStr);
which should be just:
var res = JsonConvert.DeserializeObject<Track>(jsonStr);
Your json doesn't have an array at the root level.
Full working sample:
void Main()
{
var res = JsonConvert.DeserializeObject<Track>(myJson);
}
public class Track
{
public List<Events> events { get; set; }
}
public class Events
{
public string eventID { get; set; }
public string eventType { get; set; }
public string eventDateTime { get; set; }
public string eventCreatedDateTime { get; set; }
public string eventClassifierCode { get; set; }
public string transportEventTypeCode { get; set; }
public string documentID { get; set; }
public string shipmentEventTypeCode { get; set; }
public List<DocumentReferencesMearsk> documentReferences { get; set; }
public TransportCallMaersk transportCall { get; set; }
}
public class DocumentReferencesMearsk
{
public string documentReferenceType { get; set; }
public string documentReferenceValue { get; set; }
}
public class TransportCallMaersk
{
public string transportCallID { get; set; }
public string carrierServiceCode { get; set; }
public string exportVoyageNumber { get; set; }
public string importVoyageNumber { get; set; }
public int transportCallSequenceNumber { get; set; }
public string UNLocationCode { get; set; }
public string facilityCode { get; set; }
public string facilityCodeListProvider { get; set; }
public string facilityTypeCode { get; set; }
public string otherFacility { get; set; }
public string modeOfTransport { get; set; }
public Location location { get; set; }
public Vessel vessel { get; set; }
}
public partial class Location
{
public string LocationName { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public string UnLocationCode { get; set; }
public string FacilityCode { get; set; }
public string FacilityCodeListProvider { get; set; }
}
public partial class Vessel
{
public long VesselImoNumber { get; set; }
public string VesselName { get; set; }
public string VesselFlag { get; set; }
public string VesselCallSignNumber { get; set; }
public string VesselOperatorCarrierCode { get; set; }
public string VesselOperatorCarrierCodeListProvider { get; set; }
}
static readonly string myJson = #"{
""events"": [
{
""eventID"": ""6832920321"",
""eventType"": ""SHIPMENT"",
""eventDateTime"": ""2019-11-12T07:41:00+08:00"",
""eventCreatedDateTime"": ""2021-01-09T14:12:56Z"",
""eventClassifierCode"": ""ACT"",
""shipmentEventTypeCode"": ""DRFT"",
""documentTypeCode"": ""SHI"",
""documentID"": ""205284917""
},
{
""eventID"": ""6832920321"",
""eventType"": ""TRANSPORT"",
""eventDateTime"": ""2019-11-12T07:41:00+08:00"",
""eventCreatedDateTime"": ""2021-01-09T14:12:56Z"",
""eventClassifierCode"": ""ACT"",
""transportEventTypeCode"": ""ARRI"",
""documentReferences"": [
{
""documentReferenceType"": ""BKG"",
""documentReferenceValue"": ""ABC123123123""
},
{
""documentReferenceType"": ""TRD"",
""documentReferenceValue"": ""85943567-eedb-98d3-f4ed-aed697474ed4""
}
],
""transportCall"": {
""transportCallID"": ""123e4567-e89b-12d3-a456-426614174000"",
""carrierServiceCode"": ""FE1"",
""exportVoyageNumber"": ""2103S"",
""importVoyageNumber"": ""2103N"",
""transportCallSequenceNumber"": 2,
""UNLocationCode"": ""USNYC"",
""facilityCode"": ""ADT"",
""facilityCodeListProvider"": ""SMDG"",
""facilityTypeCode"": ""POTE"",
""otherFacility"": ""Balboa Port Terminal, Avenida Balboa Panama"",
""modeOfTransport"": ""VESSEL"",
""location"": {
""locationName"": ""Eiffel Tower"",
""latitude"": ""48.8585500"",
""longitude"": ""2.294492036"",
""UNLocationCode"": ""USNYC"",
""facilityCode"": ""ADT"",
""facilityCodeListProvider"": ""SMDG""
},
""vessel"": {
""vesselIMONumber"": 1801323,
""vesselName"": ""King of the Seas"",
""vesselFlag"": ""DE"",
""vesselCallSignNumber"": ""NCVV"",
""vesselOperatorCarrierCode"": ""MAEU"",
""vesselOperatorCarrierCodeListProvider"": ""NMFTA""
}
}
}
]
}";
EDIT: Result is something like:

Deserialize shodan data

I'm having problems deserializing the data I'm getting from Shodan. Below are the classes I got from json2csharp and I'm trying to create an array of the matches and loop through them. It seems like I have tried with everything except a working array by now. The data itself is matches as root with objects of them that contain location (with its own data etc). An except below that I cut out a bit.
This is my error:
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Shodan.Match[]' because the type requ
ires a JSON array (e.g. [1,2,3]) to deserialize correctly.
var data = JsonConvert.DeserializeObject<Match[]>(allData);
{"matches": [{"product": "product", "hash": 0, "ip": 123123, "isp": "Verizon Internet Services"}], "total": 1}
public class Location
{
public string city { get; set; }
public string region_code { get; set; }
public object area_code { get; set; }
public double longitude { get; set; }
public string country_code3 { get; set; }
public double latitude { get; set; }
public string postal_code { get; set; }
public object dma_code { get; set; }
public string country_code { get; set; }
public string country_name { get; set; }
}
public class Options
{
}
public class Shodan
{
public string crawler { get; set; }
public string id { get; set; }
public string module { get; set; }
public Options options { get; set; }
}
public class Match
{
public int hash { get; set; }
public int ip { get; set; }
public string isp { get; set; }
public string transport { get; set; }
public string data { get; set; }
public string asn { get; set; }
public int port { get; set; }
public List<string> hostnames { get; set; }
public Location location { get; set; }
public DateTime timestamp { get; set; }
public List<string> domains { get; set; }
public string org { get; set; }
public object os { get; set; }
public Shodan _shodan { get; set; }
public string ip_str { get; set; }
public string product { get; set; }
}
public class RootObject
{
public List<Match> matches { get; set; }
public int total { get; set; }
}
You could create another class like
var allData =
{"matches": [{"product": "product", "hash": 0, "ip": 123123, "isp": "Verizon Internet Services"}], "total": 1}
public class MyMatches {
public Match[] matches {get; set;}
}
and then use that in the deserializer.
var data = JsonConvert.DeserializeObject<MyMatches>(allData);
This is if the JSON code sample you gave us is correct.
CORRECTION
Just saw the RootObject class.
Just use that.

c# complex and large xml loading

I have some problems parsing huge xml in c#, mostly because I returned from apex to c# after a long time. So far I cant get working even this
private void read_Click(object sender, EventArgs e)
{
XElement xmlDoc = XElement.Load(#"D:\\AOI\\Samples\\Error\\60A84130868D_20180428035150_AOI-mek1.xml");
var loaded_File =
from fileInfo in xmlDoc.Descendants("result_file")
select new File
{
filename = fileInfo.Element("designator").Value,
supplier = fileInfo.Element("supplier").Value,
date_created = fileInfo.Element("date").Value,
station_ID = fileInfo.Element("station_ID").Value,
operator_ID = fileInfo.Element("operator_ID").Value,
program = fileInfo.Element("program").Value,
side_variant = fileInfo.Element("side_variant").Value
};
foreach(var item in loaded_File) {
System.Diagnostics.Debug.WriteLine(item.ToString());
}
}
Xml file looks as follows with multiple good_no and error_no, can someone navigate me how to load the file properly? I need it afterwards to insert it into database, but that should be just fine.
<result_file>
<filename>60Axxxxxek1</filename>
<supplier>Maxxxxz</supplier>
<date>20xxxx5150</date>
<station_ID>Axxxx1</station_ID>
<operator_ID></operator_ID>
<program>Xxxx01</program>
<side_variant>A</side_variant>
<pcbs_in_panel>0</pcbs_in_panel>
<serial>60xxxxxx8D</serial>
<status>GOOD</status>
<starttime>20180xxxxxx150</starttime>
<lot_no></lot_no>
<info>
<window_no>354</window_no>
<packs_no>343</packs_no>
<error_total>1</error_total>
<error_conf>0</error_conf>
<inspection_time>5</inspection_time>
<panel_image>AOxxxxx_A.jpg</panel_image>
<panel_image_location>x:\xml</panel_image_location>
<ng_image_location>x:\xml\Xxxxx0428</ng_image_location>
<repaired>0</repaired>
</info>
<errors>
<error_no name="1">
<designator></designator>
<pin></pin>
<stamp_name>Bridge:Short</stamp_name>
<package_name></package_name>
<errortype>-</errortype>
<error_contents></error_contents>
<pcb_no></pcb_no>
<feeder_no></feeder_no>
<pos_x>8760</pos_x>
<pos_y>4600</pos_y>
<window>-313</window>
<ng_message></ng_message>
<comment>(* *){Bridge:Short}</comment>
<ng_image>Xxxxxx13.jpg</ng_image>
</error_no>
</errors>
<goods>
<good_no name="1">
<designator>Ixxx1</designator>
<pin>Ixxx1</pin>
<stamp_name>Ixxxxrat</stamp_name>
<package_name>Ixxxx1</package_name>
<pcb_no></pcb_no>
<feeder_no></feeder_no>
<pos_x>3082</pos_x>
<pos_y>3202</pos_y>
<window>+1</window>
<comment>(* *){Ixxxxat}</comment>
</good_no>
</goods>
</result_file>
Thanks for advices.
EDIT:
I have also prepared classes for that
public class File
{
public string name { get; set; }
public string filename { get; set; }
public string supplier { get; set; }
public string date_created { get; set; }
public string station_ID { get; set; }
public string operator_ID { get; set; }
public string program { get; set; }
public string side_variant { get; set; }
public string pcbs_in_panel { get; set; }
public string serial { get; set; }
public string status { get; set; }
public string starttime { get; set; }
public string lot_no { get; set; }
public string window_no { get; set; }
public string packs_no { get; set; }
public string error_total { get; set; }
public string error_conf { get; set; }
public string inspection_time { get; set; }
public string panel_image { get; set; }
public string panel_image_location { get; set; }
public string ng_image_location { get; set; }
public string repaired { get; set; }
public List<Good> Goods = new List<Good>();
public List<Error> Errors = new List<Error>();
}
public class Good
{
public List<Good_no> Good_ones = new List<Good_no>();
}
public class Error
{
public List<Error_no> Error_ones = new List<Error_no>();
}
public class Good_no
{
public string name { get; set; }
public string designator { get; set; }
public string pin { get; set; }
public string stamp_name { get; set; }
public string package_name { get; set; }
public string pcb_no { get; set; }
public string feeder_no { get; set; }
public string pos_x { get; set; }
public string pos_y { get; set; }
public string window { get; set; }
public string comment { get; set; }
}
public class Error_no
{
public string name { get; set; }
public string designator { get; set; }
public string pin { get; set; }
public string stamp_name { get; set; }
public string package_name { get; set; }
public string errortype { get; set; }
public string error_contents { get; set; }
public string pcb_no { get; set; }
public string feeder_no { get; set; }
public string pos_x { get; set; }
public string pos_y { get; set; }
public string window { get; set; }
public string ng_message { get; set; }
public string comment { get; set; }
public string ng_image { get; set; }
}
You should simplify the class structure:
public class File
{
public string Filename { get; set; }
public string Supplier { get; set; }
// ...
public List<Good> Goods { get; set; }
public List<Error> Errors { get; set; }
}
public class Good
{
public string Name { get; set; }
public string Designator { get; set; }
public string Pin { get; set; }
// ...
}
public class Error
{
public string Name { get; set; }
public string Designator { get; set; }
// ...
}
Then the reading would look like this:
var xmlDoc = XElement.Load("test.xml");
var loadedFile = new File
{
Filename = xmlDoc.Element("filename").Value,
Supplier = xmlDoc.Element("supplier").Value,
// ...
Goods = (from good in xmlDoc.Element("goods").Elements("good_no")
select new Good
{
Name = good.Attribute("name").Value,
Designator = good.Element("designator").Value,
Pin = good.Element("pin").Value
// ...
})
.ToList()
};
If you want to read the XML-File, I recommmend you to deserialize the XML-files.
For this, your class-definition isn't complete. In Visual Studio is a tool, called xsd.exe. With this tool you can transform your XML-File first in a XSD-Schema. From the XSD-Schema you can generate the required classes.
To transform to XSD-Schema: xsd.exe {Filename.xml}
To transform to C#-Classes: xsd.exe /c {Filename.xsd}
XSD have many more options (see: https://msdn.microsoft.com/de-de/library/x6c1kb0s(v=vs.120).aspx)
If you have the correct classes you can read the XML-File with the XMLSerializer (see: https://msdn.microsoft.com/de-de/library/tz8csy73(v=vs.110).aspx)

Deserializing JSON objects, keep getting errors (C#)

I am trying to deserialize my json code. The json code is in a string, and the json code looks like this (so I'm assuming it's json objects)
{
"post_id":13,
"thread_id":9,
"user_id":1,
"username":"Username",
"post_date":1496439611,
"message":"testzilla - 2133746943A9",
"ip_id":698,
"message_state":"visible",
"attach_count":0,
"position":0,
"likes":0,
"like_users":"a:0:{}",
"warning_id":0,
"warning_message":"",
"last_edit_date":1496476199,
"last_edit_user_id":0,
"edit_count":9,
"node_id":34,
"title":"Test",
"tags":"a:0:{}",
"node_title":"test node",
"node_name":null,
"message_html":"testzilla - 2133746943A9",
"absolute_url":"url"
}
How would I put the "message" container inside a string? So that the string would contain "testzilla - 2133746943A9" without the quotation marks. I am using JSON.Net
The name of the string that contains this json code is "MACs". Thanks in advance. PS: I am a new coder.
there is a missing "{" at the beginning of your json file, try adding it
You need to create your c# class to deserialize your json string. As per your json structure i have created your class given below
public class MyClass
{
public int post_id { get; set; }
public int thread_id { get; set; }
public int user_id { get; set; }
public string username { get; set; }
public int post_date { get; set; }
public string message { get; set; }
public int ip_id { get; set; }
public string message_state { get; set; }
public int attach_count { get; set; }
public int position { get; set; }
public int likes { get; set; }
public string like_users { get; set; }
public int warning_id { get; set; }
public string warning_message { get; set; }
public int last_edit_date { get; set; }
public int last_edit_user_id { get; set; }
public int edit_count { get; set; }
public int node_id { get; set; }
public string title { get; set; }
public string tags { get; set; }
public string node_title { get; set; }
public object node_name { get; set; }
public string message_html { get; set; }
public string absolute_url { get; set; }
}
No need to use library JSON.Net. You can do this by simply using System.Web.Script.Serialization to deserialize the json string.
Note : System.Web.Script.Serialization is available inside System.Web.Extensions namespace.
Below is the complete code. I kept your json data inside a file named as "test2.json" and consuming it from that file.
using System;
using System.Web.Script.Serialization;
using System.IO;
namespace DesrializeJson1ConsoleApp
{
class Program
{
static void Main(string[] args)
{
var jsonFile = "test2.json";
string jsonstring = File.ReadAllText(jsonFile);
var serializer = new JavaScriptSerializer();
MyClass aClass = serializer.Deserialize<MyClass>(jsonstring);
Console.WriteLine("--------------------------");
Console.WriteLine("message :" + aClass.message);
Console.WriteLine("message_state :" + aClass.message_state);
Console.WriteLine("warning_message :" + aClass.warning_message);
Console.WriteLine("message_html :" + aClass.message_html);
Console.WriteLine("--------------------------");
Console.Read();
}
}
public class MyClass
{
public int post_id { get; set; }
public int thread_id { get; set; }
public int user_id { get; set; }
public string username { get; set; }
public int post_date { get; set; }
public string message { get; set; }
public int ip_id { get; set; }
public string message_state { get; set; }
public int attach_count { get; set; }
public int position { get; set; }
public int likes { get; set; }
public string like_users { get; set; }
public int warning_id { get; set; }
public string warning_message { get; set; }
public int last_edit_date { get; set; }
public int last_edit_user_id { get; set; }
public int edit_count { get; set; }
public int node_id { get; set; }
public string title { get; set; }
public string tags { get; set; }
public string node_title { get; set; }
public object node_name { get; set; }
public string message_html { get; set; }
public string absolute_url { get; set; }
}
}
OUTPUT
You can use regex to get the value you want.
string yourJsonString = #"{ ""post_id"":13, ""thread_id"":9, ""user_id"":1, ""username"":""Username"", ""post_date"":1496439611, ""message"":""testzilla - 2133746943A9"", ""ip_id"":698, ""message_state"":""visible"", ""attach_count"":0, ""position"":0, ""likes"":0, ""like_users"":""a:0:{}"", ""warning_id"":0, ""warning_message"":"""", ""last_edit_date"":1496476199, ""last_edit_user_id"":0, ""edit_count"":9, ""node_id"":34, ""title"":""Test"", ""tags"":""a:0:{}"", ""node_title"":""test node"", ""node_name"":null, ""message_html"":""testzilla - 2133746943A9"", ""absolute_url"":""url""}";
string value = System.Text.RegularExpressions.Regex.Match(yourJsonString,#"""message"":(.+?),").Groups[1].Value.Replace(#"""","");
MessageBox.Show(value);
You can also use dynamic type for deserialization. You will no need to write object for deserialization:
var str = "{\r\n \"post_id\":13,\r\n \"thread_id\":9,\r\n \"user_id\":1,\r\n \"username\":\"Username\",\r\n \"post_date\":1496439611,\r\n \"message\":\"testzilla - 2133746943A9\",\r\n \"ip_id\":698,\r\n \"message_state\":\"visible\",\r\n \"attach_count\":0,\r\n \"position\":0,\r\n \"likes\":0,\r\n \"like_users\":\"a:0:{}\",\r\n \"warning_id\":0,\r\n \"warning_message\":\"\",\r\n \"last_edit_date\":1496476199,\r\n \"last_edit_user_id\":0,\r\n \"edit_count\":9,\r\n \"node_id\":34,\r\n \"title\":\"Test\",\r\n \"tags\":\"a:0:{}\",\r\n \"node_title\":\"test node\",\r\n \"node_name\":null,\r\n \"message_html\":\"testzilla - 2133746943A9\",\r\n \"absolute_url\":\"url\"\r\n}";
dynamic obj = JsonConvert.DeserializeObject(str);
var postId = obj.post_id;
Console.WriteLine("postId:" + postId);
output:
postId:13

Generate C# object from Json string and parse Json string to generated object

I am trying to generate C# class using the JSON string from here http://json2csharp.com/ this works fine. But I can't parse the JSON to the object generated by the website.
Here is the JSON string
{
"searchParameters":{
"key":"**********",
"system":"urn:oid:.8"
},
"message":" found one Person matching your search criteria.",
"_links":{
"self":{
"href":"https://integration.rest.api.test.com/v1/person?key=123456&system=12.4.34.."
}
},
"_embedded":{
"person":[
{
"details":{
"address":[
{
"line":["5554519 testdr"],
"city":"testland",
"state":"TT",
"zip":"12345",
"period":{
"start":"2003-10-22T00:00:00Z",
"end":"9999-12-31T23:59:59Z"
}
}
],
"name":[
{
"use":"usual",
"family":["BC"],
"given":["TWO"],
"period":{
"start":"9999-10-22T00:00:00Z",
"end":"9999-12-31T23:59:59Z"
}
}
],
"gender":{
"code":"M",
"display":"Male"
},
"birthDate":"9999-02-03T00:00:00Z",
"identifier":[
{
"use":"unspecified",
"system":"urn:oid:2.19.8",
"key":"",
"period":{
"start":"9999-10-22T00:00:00Z",
"end":"9999-12-31T23:59:59Z"
}
}
],
"telecom":[
{
"system":"email",
"value":"test#test.com",
"use":"unspecified",
"period":{
"start":"9999-10-22T00:00:00Z",
"end":"9999-12-31T23:59:59Z"
}
}
],
"photo":[
{
"content":{
"contentType":"image/jpeg",
"language":"",
"data":"",
"size":0,
"hash":"",
"title":"My Picture"
}
}
]
},
"enrolled":true,
"enrollmentSummary":{
"dateEnrolled":"9999-02-07T21:39:11.174Z",
"enroller":"test Support"
},
"_links":{
"self":{
"href":"https://integration.rest.api.test.com/v1/person/-182d-4296-90cc"
},
"unenroll":{
"href":"https://integration.rest.api.test.com/v1/person/1b018dc4-182d-4296-90cc-/unenroll"
},
"personLink":{
"href":"https://integration.rest.api.test.com/v1/person/-182d-4296-90cc-953c/personLink"
},
"personMatch":{
"href":"https://integration.rest.api.commonwellalliance.org/v1/person/-182d-4296-90cc-/personMatch?orgId="
}
}
}
]
}
}
Here is the code I use to convert to the object.
JavaScriptSerializer js = new JavaScriptSerializer();
var xx = (PersonsearchVM)js.Deserialize(jsonstr, typeof(PersonsearchVM));
Is there any other wat to generate the object and parse?
I think you have some invalid characters in your JSON string. Run it through a validator and add the necessary escape characters.
http://jsonlint.com/
You aren't casting it to the right object. Cast it to the type RootObject.
Eg
JavaScriptSerializer js = new JavaScriptSerializer();
var xx = (RootObject)js.Deserialize(jsonstr, typeof(RootObject));
The code that json 2 csharp creates is this:
public class SearchParameters
{
public string key { get; set; }
public string system { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class LinKs
{
public Self self { get; set; }
}
public class Period
{
public string start { get; set; }
public string end { get; set; }
}
public class Address
{
public List<string> line { get; set; }
public string city { get; set; }
public string __invalid_name__state { get; set; }
public string zip { get; set; }
public Period period { get; set; }
}
public class PerioD2
{
public string start { get; set; }
public string end { get; set; }
}
public class Name
{
public string use { get; set; }
public List<string> family { get; set; }
public List<string> given { get; set; }
public PerioD2 __invalid_name__perio
d { get; set; }
}
public class Gender
{
public string __invalid_name__co
de { get; set; }
public string display { get; set; }
}
public class Period3
{
public string start { get; set; }
public string __invalid_name__end { get; set; }
}
public class Identifier
{
public string use
{ get; set; }
public string system { get; set; }
public string key { get; set; }
public Period3 period { get; set; }
}
public class Period4
{
public string start { get; set; }
public string end { get; set; }
}
public class Telecom
{
public string system { get; set; }
public string value { get; set; }
public string use { get; set; }
public Period4 period { get; set; }
}
public class Content
{
public string contentType { get; set; }
public string language { get; set; }
public string __invalid_name__dat
a { get; set; }
public int size { get; set; }
public string hash { get; set; }
public string title { get; set; }
}
public class Photo
{
public Content content { get; set; }
}
public class Details
{
public List<Address> address { get; set; }
public List<Name> name { get; set; }
public Gender gender { get; set; }
public string birthDate { get; set; }
public List<Identifier> identifier { get; set; }
public List<Telecom> telecom { get; set; }
public List<Photo> photo { get; set; }
}
public class EnrollmentSummary
{
public string dateEnrolled { get; set; }
public string __invalid_name__en
roller { get; set; }
}
public class Self2
{
public string href { get; set; }
}
public class UnEnroll
{
public string href { get; set; }
}
public class PersonLink
{
public string href { get; set; }
}
public class PersonMatch
{
public string href { get; set; }
}
public class Links2
{
public Self2 self { get; set; }
public UnEnroll __invalid_name__un
enroll { get; set; }
public PersonLink personLink { get; set; }
public PersonMatch personMatch { get; set; }
}
public class Person
{
public Details details { get; set; }
public bool __invalid_name__e
nrolled { get; set; }
public EnrollmentSummary enrollmentSummary { get; set; }
public Links2 _links { get; set; }
}
public class Embedded
{
public List<Person> person { get; set; }
}
public class RootObject
{
public SearchParameters searchParameters { get; set; }
public string message { get; set; }
public LinKs __invalid_name___lin
ks { get; set; }
public Embedded _embedded { get; set; }
}
The following function will convert JSON into a C# class where T is the class type.
public static T Deserialise<T>(string json)
{
T obj = Activator.CreateInstance<T>();
using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
obj = (T)serializer.ReadObject(ms); //
return obj;
}
}
You need a reference to the System.Runtime.Serialization.json namespace.
The function is called in the following manner;
calendarList = Deserialise<GoogleCalendarList>(calendarListString);
calendarlist being the C# class and calendarListString the string containing the JSON.

Categories