json.net

Nested json from datatable

拜拜、爱过 提交于 2020-01-25 11:18:09
问题 I have a datatable with values like: UerId TimeStamp Parameter Value ----- --------- --------- ----- 1 03/24/2013 Param1 Value1 1 03/24/2013 Param2 Value2 1 03/24/2013 Param3 Value3 1 03/25/2013 Param4 Value4 1 03/25/2013 Param5 Value5 2 03/24/2013 Param1 Value6 2 03/24/2013 Param2 Value7 2 03/25/2013 Param1 Value8 I need to create nested json string like: Users:[ "UserId": <id>, "date":[ "TimeStamp": <TimeStamp>, "Values" : [ { "Parameter": <Parameter>, "Value": <Value> }, { "Parameter":

Nested json from datatable

非 Y 不嫁゛ 提交于 2020-01-25 11:18:06
问题 I have a datatable with values like: UerId TimeStamp Parameter Value ----- --------- --------- ----- 1 03/24/2013 Param1 Value1 1 03/24/2013 Param2 Value2 1 03/24/2013 Param3 Value3 1 03/25/2013 Param4 Value4 1 03/25/2013 Param5 Value5 2 03/24/2013 Param1 Value6 2 03/24/2013 Param2 Value7 2 03/25/2013 Param1 Value8 I need to create nested json string like: Users:[ "UserId": <id>, "date":[ "TimeStamp": <TimeStamp>, "Values" : [ { "Parameter": <Parameter>, "Value": <Value> }, { "Parameter":

In C# - How do I ignore all the attributes with the postfix Specified generated by xsd while serializing and deserializing using json.net

老子叫甜甜 提交于 2020-01-25 10:33:08
问题 I have a C# Application. I have a class that is generated from an xsd using xsd.exe. The class looks as follows public class Transaction { public bool amountSpecified {get; set;} public double amount {get; set;} } The following code shows an attempt at serialization var transObj = new Transaction(); transObj.amount = 5.10; var output =JsonConvert.Serialize(transObj); The output string doesn't contain the amount field at all. It contains amountSpecified false which I don't want in my

Loading dll that contains Newtonsoft assembly with reflection error

非 Y 不嫁゛ 提交于 2020-01-24 23:29:05
问题 I'm trying to load an assembly using reflection that uses the ISerializationBinder binder from Newtonsoft, but when the assembly is loaded it throws the following exception: System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types. Could not load type 'Newtonsoft.Json.SerializationBinder' from assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.' I don't really have a clue of why it could be 回答1: Well,

Ignore missing types during deserialization of list

时光怂恿深爱的人放手 提交于 2020-01-24 10:29:33
问题 When deserializing a list with TypeNameHandling.All , if a type namespace for one of the items is missing (deleted after serialization), it will cause a Error resolving type specified in JSON error. I wish to ignore these items instead, leaving the rest behind. Error = (sender, args) => { args.ErrorContext.Handled = true; } in JsonSerializerSettings does what I'm looking for, but will capture ALL errors of course. Is there a cleaner way of doing this, maybe via a serializer setting I've

Converting JSON object to Data.Entities.Models.MyModel

柔情痞子 提交于 2020-01-24 09:54:09
问题 So, I'm having an issue with serializing my JSON object to my Entity/Model object. I have the following code snippet: var serializedValue = JsonConvert.SerializeObject(newRows, new MyModelConverter()); var csvToSave = JsonConvert.DeserializeObject<MyModel>(serializedValue); Where newRows is a List<KeyValuePair<string,string>> Where Entity looks something like this: public class MyModel: Entity { public int Id { get; set; } //primary key public DateTime TouchTime { get; set; } public DateTime

Deserialize Dynamic JSON file C# NewtonSoft.JSON

谁说我不能喝 提交于 2020-01-24 09:20:10
问题 Working on deserializing a dynamic JSON file which could contain 2 separate classes and I won't know which type of data will be in the array. The problem is, I deserialize the root object to type "Base", "subtests" objects are deserialized to "Subtest", but the "subtests" array could be of type "Base" or of type "Subtest". QUESTION: How would I go about programatically determining that if the object contains "subtest", I deserialize to Base, and if it doesn't, it should deserialize to

Deserialize JSON text to a specific object type using the Type name [duplicate]

泄露秘密 提交于 2020-01-24 08:52:51
问题 This question already has answers here : Referencing a type from string name in a type parameter (2 answers) Closed 2 years ago . I used to deserialize JSON text to a strongly type object using the code below Trainer myTrainer = JsonConvert.DeserializeObject<Trainer>(sJsonText); Now I need to convert deserialize JSON text to a specific type knowing only the name of the type. I tried to use Reflection to get the Type from its name then use this type with JsonConvert as shown below: Type myType

JSON Parsing error with backslash

你。 提交于 2020-01-24 06:36:26
问题 I have been trying to figure out why the following JSON input will be failed to parse in JSON.parse function. {"World":"Hello\\Test"} The json above is being returned by JSON.NET. I have tried multiple methods to get this working. As you can see the backslash is escaped and https://jsonlint.com/ is able to parse it. I have a failing sample at https://jsfiddle.net/ckp0uc0p/3/ as well. Any help will be appreciated. 回答1: The best way to inject JSON into JavaScript source code (when generating

System.OutOfMemoryException when merging Newtonsoft.Json

左心房为你撑大大i 提交于 2020-01-24 04:35:12
问题 I am creating a plugin to call a webservice. I need to serialize and deserialize the Json object. So, I need Newtonsoft.Json. I am trying to merge the dll from NewtonSoft.Json and my application dll using ILMerge.MSBuild.Task and ILMerge in Visual Studio 2015. I get the error below: I looked for solution in internet but could not find any solution. 回答1: For ILMerge in VisualStudio Use the necessary dlls from NuGet Package Manager Only I was using the MSBuild.ILMerge.Task 1.0.5 and latest