json.net

Using dot notation in a JSON property name (e.g. “payment.token”)

≡放荡痞女 提交于 2019-12-10 23:08:21
问题 I am working on a script that has to make an API request. Currently, the object to send to the API looks like this: var request = new { amount = new { currency = amount.Currency, value = amount.Amount }, additionalData = new AdditionalData { ApplePayToken = paymentToken } }; The issue is, the API expects the following format to receive the additionalData property: "additionalData":{ "payment.token": "some-token" } I'm using the following code to try to reformat the object above: internal

Trim json string in JSON.NET

廉价感情. 提交于 2019-12-10 22:42:12
问题 I am using JObject.ToString() method to convert JSON object to string. But how can I trim output to delete spaces between tokens? 回答1: No need to resort to using Regex. Just use the Formatting.None option: string json = jObject.ToString(Formatting.None); 回答2: JsonConvert.SerializeObject(myJson); Json.Net SerializeObject 来源: https://stackoverflow.com/questions/28454026/trim-json-string-in-json-net

how to properly install Json.net via nuget for windows phone 7.1 and Silverlight v.4,0

喜你入骨 提交于 2019-12-10 22:15:02
问题 I need to use json.net for json serialization and deserialization, but I have the problem with installing this package. As I saw on the website it supports wp 7.1 and silverilight. When I'm typing in console Install-Package Newtonsoft.Json Installing 'Newtonsoft.Json 6.0.1'. Successfully installed 'Newtonsoft.Json 6.0.1'. Adding 'Newtonsoft.Json 6.0.1' to Connected. Uninstalling 'Newtonsoft.Json 6.0.1'. Successfully uninstalled 'Newtonsoft.Json 6.0.1'. Install failed. Rolling back... Install

How to use json.net(JObject/Jarray/Jtoken) and convert to class in the fastest way into a dictionary?

强颜欢笑 提交于 2019-12-10 22:14:53
问题 How to use json.net(JObject/Jarray/Jtoken) and convert to class in the fastest(performance) way into a dictionary? the key of the dictionary is the sees "name" in the json file Can anyone help? Thanks alot! seed.json { "Seed": [ { "name": "Cheetone", "growthrate": 1, "cost": 500 }, { "name": "Tortone", "growthrate": 8, "cost": 100 } ], } public class SoilStat { public int growthRate; public int cost; } public class DataLoader : MonoSingleton<DataLoader> { public string txt; Dictionary<string,

How to Parse Json list in VB.NET Newtonsoft

十年热恋 提交于 2019-12-10 22:14:05
问题 I receive from a webservice, the following JSON: [ {"lat": 42.41375, "user_id": 762, "user": "John", "lng": 23.02187}, {"lat": 42.46835, "user_id": 675, "user": "Mike", "lng": 23.02612}, {"lat": 42.85672, "user_id": 654, "user": "Jane", "lng": 23.01029}, {"lat": 42.46876, "user_id": 687, "user": "Luke", "lng": 23.02676} ] I want to add this information using VB.net, row by row, to a DataGridView. I'm new to JSON.net. How to loop through the whole list? How to go about parsing it? 回答1: As per

XDocument or XmlDocument to JSON with C#

喜你入骨 提交于 2019-12-10 22:05:08
问题 I have this XML which is great: <Products> <Product ProductCode="C1010" CategoryName="Coins" /> <Product ProductCode="C1012" CategoryName="Coins" /> <Product ProductCode="C1013" CategoryName="Coins" /> </Products> but it outputs to this JSON: {"Products":{"Product":[{"@ProductCode":"C1010","@CategoryName":"Coins"}, {"@ProductCode":"C1012","@CategoryName":"Coins"}, {"@ProductCode":"C1013","@CategoryName":"Coins"}]}} I would like no 'Product' sublevel in my json because all three lines are a

newtonsoft json does not serialize derived class properties

烂漫一生 提交于 2019-12-10 21:52:51
问题 I have a class structure: public class main { derived[Serializable] public class Parameters: Service.Parameters { public bool a { get; set; } public string b { get; set; } } } I am using: string jsonSerializedObject = JsonConvert.SerializeObject(model.Parameters, Formatting.None, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, }); But the properties a and b not being serialized. Any idea would be great Thank you 来源: https://stackoverflow.com/questions/18461164

Deserialize into correct child objects

爷,独闯天下 提交于 2019-12-10 21:36:34
问题 I am trying to deserialize a mix of a parent and different childs into a List<parent> . Unfortunately all the extra fields of my childs get discarded and are being serialized as a parent. I have been trying to figure out how to name the objects as a whole to link them to the correct child class. I did not have any results with this. These are a simple parent and child class i try to serialize objects from: [JsonObject(MemberSerialization.OptIn)] class Product { [JsonProperty] public string

Using Automapper to Copy Properties from a Dynamic

谁都会走 提交于 2019-12-10 20:58:42
问题 I have a dynamic object (actually, a JObject, from JSON.NET) being built dynamically from JSON. I want to have its properties copied to an existing object. The properties from the dynamic object should exist in the target object's type, if not, it's ok to have an error. I am looking at Automapper, latest version, for this. I tried to create a map from JObject to the proper type, but I don't think it'll work because the properties in the JObject are stored in an internal dictionary. Is this

json.net escaping of special characters

巧了我就是萌 提交于 2019-12-10 20:42:31
问题 Bit new to JSON so please excuse the simpleton question, but according to the list of special characters found here and here, single quote (') characters are meant to be escaped. The specification also treats solidus (/) as escapable character. To illustrate I'm using the documentation example (slightly modified). input: Product product = new Product(); product.Name = "O'Grady's Apples"; product.Expiry = new DateTime(2008, 12, 28); product.Price = 3.99M; product.Sizes = new string[] { "Small"