json.net

Deserializing JSON when fieldnames contain spaces

浪子不回头ぞ 提交于 2019-12-19 06:03:32
问题 I'm writing a tool to read JSON files. I'm using the NewtonSoft tool to deserialize the JSOn to a C# class. Here's an example fragment: "name": "Fubar", ".NET version": "4.0", "binding type": "HTTP", The field names contain spaces and other characters (the .) that are invalid in C# identifiers. What is the correct way to do this? (Unfortunately I don't have the option of changing the JSON format.) 回答1: Use the JsonProperty attribute to indicate the name in the JSON. e.g. [JsonProperty

Namespace could not be found - building using TFS [closed]

怎甘沉沦 提交于 2019-12-19 06:01:09
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I have trouble with TFS. It won't build my project because The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) I tried adding it via nuget but still I am getting this error. I have other projects which work fine when i add this

Why has JSON.NET default DateTime serialization changed?

时间秒杀一切 提交于 2019-12-19 05:03:48
问题 I've been using an old version of JSON.Net (4.0r4) for a while & have just updated to the latest one (4.5r11). I've noticed that dates used to be formatted like: 2013-03-20T09:00:00.119Z but are now: 2013-03-20T09:00:00.119 The Z is missing at the end. According to Wikipedia: If the time is in UTC, add a Z directly after the time without a space This has broken a lot of my JavaScript code as I have a method that converts this into a DateTime object & it expects the Z . I can fix it by

Json Parsing in c# using Json.Net

大城市里の小女人 提交于 2019-12-19 03:46:07
问题 {"Posts": [{"id":"1", "title":"Bibidh prothom khondo", "content":"sjih sdkljjdsf kdjsfjks", "author":"","last_update":"23 june 2013", "Comments": [{"id":"1", "content":"sjih sdkljjdsf kdjsfjks", "author":"","last_update":"23 june 2013"}]}, {"id":"2", "title":"Bibidh prothom khondo", "content":"sjih sdkljjdsf kdjsfjks", "author":"", "last_update":"24 june 2013", "Comments":[{"id":"1","content":"sjih sdkljjdsf kdjsfjks","author":"","last_update":"23 june 2013"}]},{"id":"3","title":"Bibidh

how to set the value of a json path using json.net

点点圈 提交于 2019-12-19 02:47:46
问题 I am trying to set an arbitrary path in a JSON structure and I am having difficulty figuring out how to do a simple set value... What I would like is some method like, SetValue(path,value) which operates like SelectToken, but creates the path if it does not exist and sets the value. public void SetPreference(string username, string path, string value) { var prefs = GetPreferences(username); var jprefs = JObject.Parse(prefs ?? @"{}"); var token = jprefs.SelectToken(path); if (token != null) {

Returning Raw Json in ElasticSearch NEST query

不羁岁月 提交于 2019-12-19 02:26:34
问题 I'm doing a small research about a client for elastic search in .net and I found that NEST is one of the most supported solutions for this matter. I was looking at Nest's docummentation and I couldn´t find a way to output a raw json from a query and avoid the serialization into an object, because I'm using angularJs in the front end I don´t want to overload the process of sending the information to the client with some unnecessary steps. ......and also I'd like to know how can I overrdide the

How to deserialize date (milliseconds) with JSON.NET?

六眼飞鱼酱① 提交于 2019-12-18 21:17:44
问题 I'm working with a response like the following: {"id":"https://login.salesforce.com/id/00Dx0000000BV7z/005x00000012Q9P", "issued_at":"1278448832702","instance_url":"https://na1.salesforce.com", "signature":"0CmxinZir53Yex7nE0TD+zMpvIWYGb/bdJh6XfOH6EQ=","access_token": "00Dx0000000BV7z!AR8AQAxo9UfVkh8AlV0Gomt9Czx9LjHnSSpwBMmbRcgKFmxOtvxjTrKW1 9ye6PE3Ds1eQz3z8jr3W7_VbWmEu4Q8TVGSTHxs"} I'm trying to deserialize this into a class that looks like: public class TokenResponse { public string Id {

Found conflicts between different versions of the same dependent assembly that could not be resolved error

↘锁芯ラ 提交于 2019-12-18 19:10:15
问题 Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. It's happened after I'm import Newtonsoft.Json to my App.Core(Portable) project. After look in the output: There was a conflict between "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken

How to handle deserialization of empty string into enum in json.net

旧巷老猫 提交于 2019-12-18 18:56:37
问题 I am deserializing json properties into an enum but I'm having issues handling cases when the property is an empty string. Error converting value "" to type 'EnrollmentState' I'm trying to deserialize the state property in a requiredItem . { "currentStage" : "Pre-Approved", "stages" : ["Applicant", "Pre-Approved", "Approved", "Enrolled"], "requiredItems" : [{ "id" : 1, "name" : "Documents", "state" : "" }, { "id" : 2, "name" : "Eligibility Verification", "state" : "complete" }, { "id" : 3,

Serialize Dictionary<int,object> using JSON.net?

不羁岁月 提交于 2019-12-18 17:03:22
问题 I'm trying to use JSON.net to serialize a Dictionary. Using JsonConvert.SerializeObject(theDict); Here is my result { "1": { "Blah1": false, "Blah2": false, "Blah3": "None", "Blah4": false }, "2": { "Blah1": false, "Blah2": false, "Blah3": "None", "Blah4": false }, "3": { "Blah1": false, "Blah2": false, "Blah3": "None", "Blah4": false }, ... ... ... } Is there a way to serialize this dictionary such that the keys are rendered as valid javascript variables? I am also open to other strategies