我尝试反序列化以下JSON:
"{\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.StockObject, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"1\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_16\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"2\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Weiß\",\r\n \"G_Material\": \"Leder\",\r\n \"G_Radius\": 20,\r\n \"G_Descr\": \"Weißer Fussball!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"3\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_17\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"4\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Rot\",\r\n \"G_Material\": \"Gummi\",\r\n \"G_Radius\": 15,\r\n \"G_Descr\": \"Roter Gummiball!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"5\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_18\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"6\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Orange\",\r\n \"G_Material\": \"Plastik\",\r\n \"G_Radius\": 2,\r\n \"G_Descr\": \"Tischtennisball Orange!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"7\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_19\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"8\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Gelb\",\r\n \"G_Material\": \"Gummi\",\r\n \"G_Radius\": 15,\r\n \"G_Descr\": \"Gelber Gummiball!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"9\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_20\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"10\",\r\n \"$type\": \"LLL_server.Models.ArtTypeBall, LLL_server\",\r\n \"G_Color\": \"Blau\",\r\n \"G_Material\": \"Gummi\",\r\n \"G_Radius\": 15,\r\n \"G_Descr\": \"Blauer Gummiball!\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"11\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_21\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"12\",\r\n \"$type\": \"LLL_server.Models.ArtTypeLamp, LLL_server\",\r\n \"G_Power\": 20,\r\n \"G_Descr\": \"Energiesparlampe\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"13\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_22\",\r\n \"G_ArticleType\": {\r\n \"$id\": \"14\",\r\n \"$type\": \"LLL_server.Models.ArtTypeLamp, LLL_server\",\r\n \"G_Power\": 100,\r\n \"G_Descr\": \"Helle Lampe\"\r\n },\r\n \"G_Place\": null,\r\n \"G_Position\": null,\r\n \"G_StoredAt\": \"0001-01-01T00:00:00\"\r\n },\r\n {\r\n \"$id\": \"15\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_1\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"2\"\r\n },\r\n \"G_Place\": {\r\n \"$id\": \"16\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_1\",\r\n \"G_Stock\": {\r\n \"$id\": \"17\",\r\n \"$type\": \"LLL_server.Models.Stock, LLL_server\",\r\n \"G_PlaceList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Place, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"16\"\r\n },\r\n {\r\n \"$id\": \"18\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_2\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"19\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_3\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"20\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_4\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"21\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_5\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"22\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_6\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"23\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_7\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"24\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_8\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"25\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_9\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n },\r\n {\r\n \"$id\": \"26\",\r\n \"$type\": \"LLL_server.Models.Place, LLL_server\",\r\n \"G_Name\": \"Platz_10\",\r\n \"G_Stock\": {\r\n \"$ref\": \"17\"\r\n }\r\n }\r\n ]\r\n }\r\n }\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"27\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_1\",\r\n \"G_Order\": {\r\n \"$id\": \"28\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"27\"\r\n },\r\n {\r\n \"$id\": \"29\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_2\",\r\n \"G_Order\": {\r\n \"$ref\": \"28\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"30\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_3\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"4\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"18\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"29\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"15\"\r\n },\r\n {\r\n \"$id\": \"31\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_2\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"2\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"16\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"27\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5850625\"\r\n },\r\n {\r\n \"$ref\": \"31\"\r\n },\r\n {\r\n \"$ref\": \"30\"\r\n },\r\n {\r\n \"$id\": \"32\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_4\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"6\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"19\"\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"33\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_3\",\r\n \"G_Order\": {\r\n \"$id\": \"34\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"33\"\r\n },\r\n {\r\n \"$id\": \"35\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_4\",\r\n \"G_Order\": {\r\n \"$ref\": \"34\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"36\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_5\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"12\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"20\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"35\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n },\r\n {\r\n \"$id\": \"37\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_5\",\r\n \"G_Order\": {\r\n \"$ref\": \"34\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"38\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_6\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"8\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"21\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"37\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"32\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$ref\": \"36\"\r\n },\r\n {\r\n \"$ref\": \"38\"\r\n },\r\n {\r\n \"$id\": \"39\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_7\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"10\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"21\"\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"40\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_6\",\r\n \"G_Order\": {\r\n \"$id\": \"41\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"40\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"39\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$id\": \"42\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_8\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"12\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"21\"\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"43\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_7\",\r\n \"G_Order\": {\r\n \"$id\": \"44\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"43\"\r\n },\r\n {\r\n \"$id\": \"45\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_8\",\r\n \"G_Order\": {\r\n \"$ref\": \"44\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"46\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_9\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"8\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"22\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"45\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n },\r\n {\r\n \"$id\": \"47\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_9\",\r\n \"G_Order\": {\r\n \"$ref\": \"44\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"48\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_10\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"12\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"23\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"47\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"42\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$ref\": \"46\"\r\n },\r\n {\r\n \"$ref\": \"48\"\r\n },\r\n {\r\n \"$id\": \"49\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_11\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"6\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"24\"\r\n },\r\n \"G_Position\": {\r\n \"$id\": \"50\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_10\",\r\n \"G_Order\": {\r\n \"$id\": \"51\",\r\n \"$type\": \"LLL_server.Models.Order, LLL_server\",\r\n \"G_CompletelyPicked\": false,\r\n \"G_PositionList\": {\r\n \"$type\": \"System.Collections.Generic.List`1[[LLL_server.Models.Position, LLL_server]], mscorlib\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"50\"\r\n },\r\n {\r\n \"$id\": \"52\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_11\",\r\n \"G_Order\": {\r\n \"$ref\": \"51\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"53\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_12\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"4\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"25\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"52\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n },\r\n {\r\n \"$id\": \"54\",\r\n \"$type\": \"LLL_server.Models.Position, LLL_server\",\r\n \"G_Code\": \"POSITION_12\",\r\n \"G_Order\": {\r\n \"$ref\": \"51\"\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$id\": \"55\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_13\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"14\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"26\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"54\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$id\": \"56\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_14\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"14\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"26\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"54\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$id\": \"57\",\r\n \"$type\": \"LLL_server.Models.StockObject, LLL_server\",\r\n \"G_Code\": \"OBJECT_15\",\r\n \"G_ArticleType\": {\r\n \"$ref\": \"14\"\r\n },\r\n \"G_Place\": {\r\n \"$ref\": \"26\"\r\n },\r\n \"G_Position\": {\r\n \"$ref\": \"54\"\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n },\r\n \"G_Picked\": false,\r\n \"G_ObjectList\": {\r\n \"$type\": \"NHibernate.Collection.Generic.PersistentGenericBag`1[[LLL_server.Models.StockObject, LLL_server]], NHibernate\",\r\n \"$values\": [\r\n {\r\n \"$ref\": \"49\"\r\n }\r\n ]\r\n }\r\n },\r\n \"G_StoredAt\": \"2018-06-09T23:48:06.5860626\"\r\n },\r\n {\r\n \"$ref\": \"53\"\r\n },\r\n {\r\n \"$ref\": \"55\"\r\n },\r\n {\r\n \"$ref\": \"56\"\r\n },\r\n {\r\n \"$ref\": \"57\"\r\n }\r\n ]\r\n}"
使用JSON.NET。它是用JSON.NET创建的。
我希望从中创建实例的类:
public class StockObject
{
public ArticleType G_ArticleType { get; set; }
public string G_Code { get; set; }
public Place G_Place { get; set; }
public Position G_Position { get; set; }
public string G_StoredAt { get; set; }
public string Id { get; set; }
public DateTime ReturnStoredAt
{
get { return DateTime.ParseExact(G_StoredAt, "o", CultureInfo.InvariantCulture); }
set { G_StoredAt = value.ToString("o"); }
}
}
public class ArticleType
{
public string G_Descr { get; set; }
public string Id { get; set; }
public string Type { get; set; }
}
public class ArtTypeBall : ArticleType
{
public string G_Color { get; set; }
public string G_Material { get; set; }
public string G_Radius { get; set; }
public string G_Power { get; set; }
}
public class ArtTypeLamp : ArticleType
{
public string G_Power { get; set; }
}
public class Place
{
public string G_Name { get; set; }
public Stock G_Stock { get; set; }
public string Id { get; set; }
}
public class Stock
{
public List<Place> G_PlaceList { get; set; }
}
public class Position
{
public string G_Code { get; set; }
public List<StockObject> G_ObjectList { get; set; }
public Order G_Order { get; set; }
public string G_Picked { get; set; }
public string Id { get; set; }
}
public class Order
{
public string G_CompletelyPicked { get; set; }
public List<Position> G_PositionList { get; set; }
public string Id { get; set; }
}
创建JSON的服务器端代码:
[HttpGet]
public string GetAllStockObjects()
{
var L_ObjectList = G_Repository.ReadAll();
var L_Settings = new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.All
};
return JsonConvert.SerializeObject(L_ObjectList, Formatting.Indented, L_Settings);
}
和反序列化代码:
class ObjectDataCollection : ObservableCollection<ObjectData>
{
public HttpClient G_Client { get; set; }
public ObjectDataCollection()
{
G_Client = new HttpClient();
G_Client.BaseAddress = new Uri("http://localhost:50115/");
G_Client.DefaultRequestHeaders.Accept.Clear();
G_Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
this.Initialize();
}
private async void Initialize()
{
List<StockObject> L_ObjectList = await GetObjectsAsync();
foreach (StockObject L_Object in L_ObjectList)
{
string L_Place;
string L_Position;
string L_ArticleType;
if (L_Object.G_Place != null)
{
L_Place = L_Object.G_Place.G_Name;
}
else
{
L_Place = "null";
}
if (L_Object.G_Position != null)
{
L_Position = L_Object.G_Position.G_Code;
}
else
{
L_Position = "null";
}
if (L_Object.G_ArticleType != null)
{
L_ArticleType = L_Object.G_ArticleType.G_Descr;
}
else
{
L_ArticleType = "null";
}
this.Add(new ObjectData()
{
G_Code = L_Object.G_Code,
G_Place = L_Place,
G_Position = L_Position,
G_ArticleType = L_ArticleType,
});
}
}
private async Task<List<StockObject>> GetObjectsAsync()
{
List<StockObject> L_ObjectList = null;
HttpResponseMessage L_Response = await G_Client.GetAsync("api/stockobject/getallstockobjects");
if (L_Response.IsSuccessStatusCode)
{
string L_ResponseAsString = await L_Response.Content.ReadAsStringAsync();
L_ObjectList = Deserialize<List<StockObject>>(L_ResponseAsString);
}
return L_ObjectList;
}
private T Deserialize<T>(string I_JSON)
{
var L_Settings = new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.All
};
return JsonConvert.DeserializeObject<T>(I_JSON, L_Settings);
}
}
class ObjectData
{
public string G_Place { get; set; }
public string G_Position { get; set; }
public string G_Code { get; set; }
public string G_ArticleType { get; set; }
}
错误消息:
无法从System.String转换或转换为System.Collections.Generic.List`1 [TestClientArno.Models.StockObject]。
我也尝试过:
L_ObjectList = Deserialize<IEnumerable<StockObject>>(L_ResponseAsString);
但这也没有用。 我确定我在客户端的课程是错的,但我看不到在哪里。
问候, 罗伯特
答案 0 :(得分:1)
虽然我理解Eser的观点(API应该尽可能轻量化),但我会为每个想要这样的API(保留引用和继承)的人发布我的解决方案:
我惊讶地发现,你只需使用它的默认json-serializer就可以将Json.Net序列化器与web API 2一起使用。 webapiconfig.cs应如下所示:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web-API-Routen
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Web-API-Konfiguration und -Dienste
var L_SerBinder = new SerBinder();
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.JsonFormatter.SerializerSettings.SerializationBinder = L_SerBinder;
}
}
这里是SerBinder类,它是避免命名空间问题所必需的:
public class SerBinder : ISerializationBinder
{
public IList<Type> G_KnownTypes;
public SerBinder()
{
G_KnownTypes = new List<Type>();
G_KnownTypes.Add(typeof(ArticleType));
G_KnownTypes.Add(typeof(ArtTypeBall));
G_KnownTypes.Add(typeof(ArtTypeLamp));
G_KnownTypes.Add(typeof(Stock));
G_KnownTypes.Add(typeof(StockObject));
G_KnownTypes.Add(typeof(Order));
G_KnownTypes.Add(typeof(Position));
G_KnownTypes.Add(typeof(Place));
}
public Type BindToType(string assemblyName, string typeName)
{
return G_KnownTypes.SingleOrDefault(t => t.Name == typeName);
}
public void BindToName(Type serializedType, out string assemblyName, out string typeName)
{
assemblyName = null;
typeName = serializedType.Name;
}
}
你还需要
using Newtonsoft.Json.Serialization;
表示“ISerializationBinder” - 接口。 必须使用要反序列化的所有类名填充G_KnownTypes。
在客户端:
private T Deserialize<T>(string I_JSON)
{
var L_SerBinder = new SerBinder();
var L_Settings = new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Objects,
SerializationBinder = L_SerBinder,
};
return JsonConvert.DeserializeObject<T>(I_JSON, L_Settings);
}
当然,您必须在客户端实现相同的SerBinder类。