json.net

Deserializing JSON child object values into parent object using JsonConvert.DeserializeObject<T> using nested converters

眉间皱痕 提交于 2019-12-11 09:53:04
问题 I'm receiving some oddly formatted JSON that I want to store in a single object. It looks something like this: { "parentObject": { "id": 123456, "pointlessChildObject": { "stringThatCouldBeStoredInParent": "test", "epochTimeThatCouldBeStoredInParent": "1520452800" } } } At first, I thought this would be simple thanks to a solution by Brian Rogers that I found: Can I specify a path in an attribute to map a property in my class to a child property in my JSON? However, if you implement this

Trying to deserialize JSON using JSON.NET and DataContractJsonSerializer fails

廉价感情. 提交于 2019-12-11 09:36:45
问题 plz help, I'm stuck. I have a WCF service which returns something like this: { "GetDataRESTResult": [ {"Key1":100.0000,"Key2":1,"Key3":"Min"}, {"Key1":100.0000,"Key2":2,"Key3":"Max"} ] } and I would like to deserialize it, but whatever I use (JSON.NET or DataContractJsonSerializer) I'm getting errors. When using DataContractJsonSerializer I'm using theis code: byte[] data = Encoding.UTF8.GetBytes(e.Result); MemoryStream memStream = new MemoryStream(data); DataContractJsonSerializer serializer

deserializing Static properties using json.net?

陌路散爱 提交于 2019-12-11 09:27:50
问题 Hi guys I have a JSON like the one below { "totals": { "tokenType": "string", "tokenDenomination": "double", "count": "int" }, "IDCode": "string", "Key": "string" } and c# code to deserialize in to object is internal class GetTokenRootInfo { public static Totals totals{ get; set;} public static string IDCode{ get; set;} public static string Key{ get; set;} } When I use jsonconvert.DeserializeObject<gettokenrootinfo>(json); nothing is being set and every var is a null. But if I remove static

Converting a DataTable to nested JSON output

北慕城南 提交于 2019-12-11 09:13:34
问题 I have a SQL Server source table defined as: sku store qty 20000 100 3 20000 132 1 20000 320 0 30000 243 2 30000 210 1 10000 410 5 I need the output to be: { "skus": { "20000": { "100": 3, "132": 1, "320": 0 }, "30000": { "243": "2", "410": "1" }, "10000": { "410": "5" } } } I have the source SQL Server table being imported to a DataSet, then was going to use JSON.NET to parse the results. I was thinking I should create some sort of Class structure with a sku having a list of store/qty key

Dictionary<string, JToken> recursive search

帅比萌擦擦* 提交于 2019-12-11 09:01:48
问题 I have DeserializeObject to a C# object however I have objects with dynamic object names so I have structured it like this: public class RootObject { public string name { get; set; } public TableLayout table{ get; set; } } public class TableLayout { public Attributes attributes { get; set; } //Static public Info info { get; set; } //Static [JsonExtensionData] public Dictionary<string, JToken> item { get; set; } } So basically any dynamic objects that appear will be added to the dictionary and

How to convert c# arrays to JSON with one array item propety value set as reference to item from another

拜拜、爱过 提交于 2019-12-11 08:57:14
问题 To properly bind Java script arrays to AngularJs view I need them look like: var ingridients = [ {name: 'Vodka'}, {name: 'Gin'}, {name: 'Rum'} ]; var drinks = [ {name: 'Bloody Mary', basicIngridient: ingridients[0]}, {name: 'Gin & Tonic', basicIngridient: ingridients[1]}, {name: 'Daiquiry', basicIngridient: ingridients[2]} ]; Suppose I have c# arrays like: class Drink { public string Name { get; set; } public Ingridient BasicIngridient { get; set; } } class Ingridient { public string Name {

how to parse nested JSON response asp.net (vb.net)

情到浓时终转凉″ 提交于 2019-12-11 08:49:43
问题 I have a JSON response that I need to parse into an object in ASP.Net (Vb.net or c#), but I don't see any examples for a nested response string and how to parse (only simple value pairs). Here's one: { "ticker": { "high": 3.494, "low": 2.9, "avg": 3.197, "vol": 463260.58724, "vol_cur": 143878.12481, "last": 2.924, "buy": 2.959, "sell": 2.925, "updated": 1387635241, "server_time": 1387635242 } } from one site, and another one here: { "result": "success", "return": { "high": { "value": "745

JSONConvert.DeserializeObject not handling child array with unnamed array items

本小妞迷上赌 提交于 2019-12-11 08:36:33
问题 I have the following JSON object coming to me from a web service { "room":{ "name":"Thunderdome", "created_at":"2012/04/15 00:36:27 +0000", "id":xxxxxxx, "users":[ { "type":"Member", "avatar_url":"url", "created_at":"2012/02/27 14:11:57 +0000", "id":1139474, "email_address":"xxx@xxxxxxx.com", "admin":false, "name":"xxxx xxxxx" }, { "type":"Member", etc I'm using the following line to deserialize: var room = JsonConvert.DeserializeObject<SingleRoom>(text); And the following mapping classes

JsonConvert .NET Serialize/Deserialize Read Only [duplicate]

百般思念 提交于 2019-12-11 08:26:56
问题 This question already has answers here : Making a property deserialize but not serialize with json.net (10 answers) Closed 2 years ago . I'm working with a REST Api at the moment which I have no control over and have built models to correspond with the json which I receive from the Api. The Api in question though doesn't allow me to push the whole model back when doing a post so I need to find a way to Deserialize the json in full but only write selected data when Serializing. So far I have

Accessing multiple arrays in JSON using C#

青春壹個敷衍的年華 提交于 2019-12-11 08:14:14
问题 My JSON looks like this: {"2013" : [ { "date":"2013-01-09 12:00:00","height":0 }, { "date":"2013-01-19 12:00:00","height":3 }, { "date":"2013-01-29 12:00:00","height":2 }], "2012" : [ { "date":"2012-02-09 12:00:00","height":0 }, { "date":"2012-02-19 12:00:00","height":4 }, { "date":"2012-02-29 12:00:00","height":2 }], "2011" : [ { "date":"2011-03-09 12:00:00","height":3 }, { "date":"2011-03-19 12:00:00","height":8 }, { "date":"2011-03-29 12:00:00","height":2 }] } What I am trying to do is get