json.net

Error while deserializing with JSON.NET

删除回忆录丶 提交于 2019-12-13 04:07:01
问题 i try to deserialize the following 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\": \

Deserializing JSON objects to an array

时光怂恿深爱的人放手 提交于 2019-12-13 03:59:36
问题 I have an API that gives me a list of similar items as different object instead that as members of an array. Let's see the _items node, which contains the available items on a store: { "_ok":200, "_store": { "location":"Rome", "open":true }, "_items": { "itemA":{ "color":"blue","size":3}, "itemB":{ "color":"red","size":1}, "itemC":{ "color":"cyan","size":3}, "itemD":{ "color":"yellow","size":0}, } } I am using the very nice Newtonsoft JSON.NET to do my deserialization, but I do not know how

Deserializing Circular References by Two-Phase deserialization

痞子三分冷 提交于 2019-12-13 03:50:03
问题 I have a Serializer/Deserializer that use a references PreserveReferencesHandling = PreserveReferencesHandling.All . The issue, is that I have circular references. Here is a very simple example. class Node { public Node(object value) { Value = value; } public object Value { get; set; } public Node Left { get; set; } public Node Right { get; set; } } My test scenario is: var obj = new Node("o") { Left = new Node("oL"), Right = new Node("oR") }; obj.Right.Right = obj; // Circular reference!

How to serialize-deserialize any of 3 object types, one of which contains an abstract class?

折月煮酒 提交于 2019-12-13 03:39:43
问题 I am sending 3 .net objects over the network: - List<int> - List<ParentObject> - string This is how I'm serializing (same for all types): JsonSerializerSettings JSsettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Arrays }; string message = JsonConvert.SerializeObject(listOfParents, JSsettings); //listOfParents is of type List<ParentObject> The ParentObject is an abstract class and has two child classes. It has a property to get which child type it represents. public

How to parse two different JSON formats

↘锁芯ラ 提交于 2019-12-13 03:25:23
问题 I need to parse 2 different types of JSONs as shown below: JSON 1: { "projects": [ { "sno": "1", "project_name": "Abs", "project_Status": "Live" }, { "sno": "2", "project_name": "Cgi", "project_Status": "Live" } ] } JSON 2: [ { "sno": "1", "project_name": "Disc", "project_Status": "Live" }, { "sno": "2", "project_name": "Rol", "project_Status": "Live" } ] I was parsing the JSON 2 as follows: using (StreamReader streamReader = new StreamReader(Path.Combine(Path.GetTempPath(), "sample.json")))

Json path query in JObject.SelectTokens in Json.net not returning results

做~自己de王妃 提交于 2019-12-13 03:24:04
问题 I have a json like this { "Attributes": [ { "Name": "attr1", "Value": "abcd" }, { "Name": "attr2", "Value": "abcde" }, { "Name": "attr3", "Value": "abcdef" } ], "SomeObject": { "Attributes": [ { "Name": "attr1", "Value": "xyz" }, { "Name": "attr2", "Value": "xyza" }, { "Name": "attr3", "Value": "wxyxz" } ] } } I am implementing a common code. Every time the object structure may change, But the attributes structure is going to remain same. I want find all the attributes by matching their name

C# - Unexpected character encountered while parsing value: {. Path '[0].Statistics

廉价感情. 提交于 2019-12-13 03:22:55
问题 I am trying to deserialize a JSON object according to my model using the code below: LoadData<MyModel>(Data.Stats, null); public void LoadData<TModel>(string data, JsonSerializerSettings jsonSettings) where TModel : class { var mockData = JsonConvert.DeserializeObject<Collection<TModel>>(data, jsonSettings); // ERROR HERE Context.SaveChanges(); } However I am getting an error that reads Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: {. Path '[0]

Attempt to access the method failed: System.Collections.Generic.List`1..ctor()

谁说我不能喝 提交于 2019-12-13 02:33:52
问题 I've this code through which I am retrieveing json data from my Localhost.But it is giving the error mentioned in my title.When I hover over the response while debugging.It shows me the correct response.I am using JSON.NET to parse json response. var response = reader.ReadToEnd(); List<Company> cLst = JsonConvert.DeserializeObject<List<Company>>(response); //Error this.Dispatcher.BeginInvoke(() => { foreach (Company c in cLst) { ListBoxItemControl Li = new ListBoxItemControl(); Li

How to deserialize a JSON array containing different data types to a single object

六眼飞鱼酱① 提交于 2019-12-13 02:22:38
问题 Over the last few days I have been researching on how to deserialize a JSON response to and C# object. The JSON is valid but I can not get any JSON to C# converters to convert it. I also cannot find an answer on Stackoverflow that works for this instance. The JSON Response is: [ { "SEX": "Male", "BREED": "Opifex", "PVPRATING": 1301, "NAME": "Kilmanagh", "FIRSTNAME": "Big", "PVPTITLE": "Freshman", "LASTNAME": "Kahuna", "CHAR_DIMENSION": 5, "ALIENLEVEL": 30, "RANK_name": "Vindicator", "HEADID":

Problems Deserializing Nested JSON Array in C#

删除回忆录丶 提交于 2019-12-13 01:51:23
问题 Edit I notice this is getting negative votes, I imagine it's for not showing research effort. I've looked at a lot of stack overflow posts. I can't find an example with JSON this heavily nested that has been accessed with examples of how the data stored in the JSON has been manipulated afterwards. Problem and Aim Using restsharp I've received a JSON response to an API call I made however I'm struggling to deserialize the response I'm getting. The data I want to use seems to be a nested array