json.net

Deserializing a string property value to a class instance using JSON.Net

隐身守侯 提交于 2019-12-13 01:47:28
问题 I'm deserializing some JSON from a server which is, for the most part, simple: { "id": "ABC123" "number" 1234, "configured_perspective": "ComplexPerspective[WithOptions,Encoded]" } That "configured_perspective" property, however, is an unfortunate case of the server using a weirdly put-together string when a nested object would have been better. To ease the suffering of our .NET users, I convert this into a custom class in my object model: public class Example { public string id { get; set; }

JSON.NET Dynamic Parsing (More Efficient Solution)

狂风中的少年 提交于 2019-12-13 01:24:18
问题 so I'm using JSON.NET to parse JSON data. I have got dynamic parsing using JObject class to work but I'm looking for a more efficient way. This is just the basics and my final solution will be much more complicated, but first thing's first, I need to get the basics. So I have this JSON data... { "count":1, "results": [{ "user_id":5029420, "login_name":"EtsyStore", "creation_tsz":1282269739, "referred_by_user_id":null, "feedback_info": { "count":3038, "score":100 } }], "params": { "user_id":

Google.Apis.Json.NewtonsoftJsonSerializer throw an exception

点点圈 提交于 2019-12-13 01:03:38
问题 When I run workerRole on Azure, throw me the following exception: An unhandled exception of type 'System.TypeInitializationException' occurred in Google.Apis.Auth.dll Additional information: Se produjo una excepción en el inicializador de tipo de 'Google.Apis.Json.NewtonsoftJsonSerializer'. This is the code that break execution: private static byte[] jsonSecrets = Properties.Resources.client_secrets; using (var stream = new MemoryStream(jsonSecrets, true)) { GoogleWebAuthorizationBroker

How do I deserialize an array of objects with varying names?

穿精又带淫゛_ 提交于 2019-12-13 00:36:30
问题 In a Windows Phone app using C#, I am trying to deserialize some JSON with the following structure: [ { "kite" : { "supplier" : "ABC", "currency" : "GBP", "cost" : "7.98" } }, { "puzzle" : { "supplier" : "DEF", "currency" : "USD", "cost" : "7.98" } }, { "ball" : { "supplier" : "DEF", "currency" : "USD", "cost" : "5.49" } } ] This is a list of toys in which the names of the toys (kite, puzzle, ball) are not known in advance. I don't have any control over the format of the JSON. Using

Creating a double serialized JSON object in REST SOE C#

为君一笑 提交于 2019-12-13 00:16:10
问题 I'm not sure if I'm double-serializing my JSON object, but the output results in an unwanted format. I'm exposing the REST endpoint via an ArcGIS Server Object Extension (REST SOE). I've also recently implemented JSON.Net which essentially allowed me to remove several lines of code. So here is the handler, which is the core piece creating the data for the service (for you non GIS peeps). private byte[] SearchOptionsResHandler(NameValueCollection boundVariables, string outputFormat, string

Is possible optimize json.net schema with JSchemaValidatingReader to deserialize in object in same read of stream?

我与影子孤独终老i 提交于 2019-12-13 00:05:32
问题 I'm trying a poc. Is possible optimize json.net schema with JSchemaValidatingReader to deserialize in object in same read of stream? In otherworld string schemaJson = @"{ 'description': 'A person', 'type': 'object', 'properties': { 'name': {'type': 'string'}, 'hobbies': { 'type': 'array', 'items': {'type': 'string'} } } }"; JSchema schema = JSchema.Parse(schemaJson); using (StreamReader s = File.OpenText(@"c:\bigdata.json")) using (JSchemaValidatingReader reader = new JSchemaValidatingReader

Serializing Dictionary<string,string> to array of “name”: “value”

三世轮回 提交于 2019-12-12 23:18:16
问题 I have this simple model in an ASP.NET WebAPI 2 application: public class Model { public int ID { get; set; } public Dictionary<string, string> Dic { get; set; } } When it gets serialized, the output is: { "ID": 0, "Dic": { "name1": "value1", "name2": "value2" } } I searched the problem, but it seems most people need this serialization: { "ID": 0, "Dic": [{ "Key": "name1", "Value": "value1" }] } And all solutions out there are resolving to that kind of serialization. But what I'm looking for

Read data from json into class and store into database sqlserver

旧时模样 提交于 2019-12-12 22:25:22
问题 class Program { static void Main(string[] args) { //This is your input json string var inputJson = @"{ 'datamapItems': [ { 'paramName': 'VE8321C', 'datamapKey': { 'module': 1, 'id': 1391 }, 'min': '0', 'max': '40', 'default': 222, 'rateHz': 0, 'timeoutMs': 0, 'dataType': 'uint16' } ] }"; clsJSON result = JsonConvert.DeserializeObject<clsJSON>(inputJson); } } public class clsJSON { public Datamap datamap; } public class Datamap { [JsonExtensionData] public Dictionary<string, JToken>

Ignore UTC offsets when deserializing with Json.NET

心不动则不痛 提交于 2019-12-12 20:50:28
问题 I've written a REST endpoint with ASP.NET Web API 2 that receives dates. The backend system has no concept of UTC times or DST, the dates stored in the database are just the UK date and time. The website feeding the endpoint, however, is including UTC offset values in the data sent to the end point (e.g. a date looks like "1939-01-08T00:00:00+01:00"). This happens when a summer date is entered in the winter or vice-versa (because of the adjustment for DST). Is it possible for me to set the

BsonSerializationException occurs if element name ends in a period

那年仲夏 提交于 2019-12-12 19:22:59
问题 I am writing a C# application that reads from an XML file, converts that to JSON, and uploads to MongoDB. Some of our tags are structured with a period at the end, like so: <BatteryTest.>GOOD</BatteryTest.> Using the Newtonsoft library I am able to convert the XML to JSON without a problem. It is when I go to deserialize it to a BsonDocument that I have trouble: var document = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(jsonText); I get the following error message: An