json.net

json.net: DateTimeStringConverter gets an already DateTime converted object in ReadJson()

偶尔善良 提交于 2021-01-13 09:35:27
问题 Prerequisites: JSON.Net 11.0.2 I need to store the UTC DateTime round-trip date/time pattern via a JSON based REST-API. string utcTimestamp = DateTime.UtcNow.ToString( "o" ); // 2018-11-27T22:35:32.1234567Z So I wrote myself a DateTimeStringConverter to ensure no local culture information gets involved. class DateTimeStringConverter: JsonConverter<DateTime> { public override void WriteJson( JsonWriter writer, DateTime value, JsonSerializer serializer ) { string convertedValue = value.ToString

笔记-ASP.NET WebApi

自作多情 提交于 2021-01-10 07:24:18
本文是针对ASP.NET WepApi 2 的笔记。 Web API 可返回的结果: 1.void 2.HttpResponseMessage 3.IHttpActionResult 4.其他类型 返回类型 Web API创建响应的方式 void HTTP204(无内容) HttpResponseMessage 转换为HTTP响应消息 IHttpActionRsult 调用ExecuteAsync来创建HttpResponseMessage,然后转换为HTTP响应消息 其他类型 将序列化的返回值写到响应正文中,返回HTTP200 路由 路由表:Web API的默认路由模板"api/{controller}/{id}",此模板中,"api"是文本路径段,{controller}和{id}是占位符变量。 路由变体:可以显示指定Action的HTTP方法,如HttpGet,HttpPost。 public class ProductsController : ApiController { [HttpGet] public Product FindProduct(id) {} } 若要允许多个HTTP方法或GET,POST,PUT,DELETE以外的HTTP方法,可以显示使用 AcceptVerbs 属性: public class ProductsController :

Unable to cast string to type with implicit conversion

早过忘川 提交于 2021-01-07 06:38:35
问题 I am trying to serialize JSON into a data structure with the types from the OneOf library, using JSON.NET, using a custom converter. I am encountering the following exception: System.InvalidCastException: 'Unable to cast object of type 'System.String' to type 'System.Nullable`1[OneOf.OneOf`2[OneOf.OneOf`2[PandocFilters.TagContent,System.Int64][],System.String]]'.' Which doesn't make sense to me, because the following C# code compiles and runs: OneOf<OneOf<TagContent, long>[], string>? c =

Unable to cast string to type with implicit conversion

北战南征 提交于 2021-01-07 06:36:13
问题 I am trying to serialize JSON into a data structure with the types from the OneOf library, using JSON.NET, using a custom converter. I am encountering the following exception: System.InvalidCastException: 'Unable to cast object of type 'System.String' to type 'System.Nullable`1[OneOf.OneOf`2[OneOf.OneOf`2[PandocFilters.TagContent,System.Int64][],System.String]]'.' Which doesn't make sense to me, because the following C# code compiles and runs: OneOf<OneOf<TagContent, long>[], string>? c =

JObject tostring formatting issue for JArray

 ̄綄美尐妖づ 提交于 2021-01-07 01:29:33
问题 I have a question or rather an issue with the JObject. This is just a small example, I have large lists with more than 20 elements and I am saving these in JSON format and it is really bad to read if every value is in a new line. Can someone explain to me how to fix this? Code: var myObj = new { Vector = new List<int>{ 1,2,3,4,5 } }; Console.WriteLine(JToken.FromObject(myObj).ToString(Formatting.Indented)); Output is like this: { "Vector": [ 1, 2, 3, 4, 5 ] } But I want it to be like this: {

Newtonsoft.Json works in Unity Editor but not on mobile devices

怎甘沉沦 提交于 2021-01-05 14:47:15
问题 I am programming a game of questions and answers by categories in Unity. The categories are obtained through a PHP script that returns a JSON text, * when I use this solution in the UnityEditor it works correctly, but when I install the .apk on my mobile device, deserialization does not work* . The connection to the mysql database and the PHP scripts work correctly because before I log in and it works fine string json = [ { "id_cat":"1", "nombre_cat":"DAM", "id_cat_padre":"0" }, { "id_cat":"4

Newtonsoft.Json works in Unity Editor but not on mobile devices

人盡茶涼 提交于 2021-01-05 14:46:09
问题 I am programming a game of questions and answers by categories in Unity. The categories are obtained through a PHP script that returns a JSON text, * when I use this solution in the UnityEditor it works correctly, but when I install the .apk on my mobile device, deserialization does not work* . The connection to the mysql database and the PHP scripts work correctly because before I log in and it works fine string json = [ { "id_cat":"1", "nombre_cat":"DAM", "id_cat_padre":"0" }, { "id_cat":"4

Newtonsoft.Json works in Unity Editor but not on mobile devices

醉酒当歌 提交于 2021-01-05 14:45:00
问题 I am programming a game of questions and answers by categories in Unity. The categories are obtained through a PHP script that returns a JSON text, * when I use this solution in the UnityEditor it works correctly, but when I install the .apk on my mobile device, deserialization does not work* . The connection to the mysql database and the PHP scripts work correctly because before I log in and it works fine string json = [ { "id_cat":"1", "nombre_cat":"DAM", "id_cat_padre":"0" }, { "id_cat":"4

Can I deserialize Json to class like C# Newtonsoft in Python

∥☆過路亽.° 提交于 2021-01-04 05:51:55
问题 This is json {"name":"david","age":14,"gender":"male"} This is python class class Person: def __init__(self): self.name = None self.age = None self.gener = None self.language = None this is Code #deserialize func~~~~~ print person.name #prints david print person.age #prints 14 print person.gender #prints male print person.language #prints "None" Can I deserialize Json to class in Python(like C# Newtonsoft) Thank you. 回答1: You can use it with the json.loads() method. You would also need to

Can I deserialize Json to class like C# Newtonsoft in Python

笑着哭i 提交于 2021-01-04 05:49:17
问题 This is json {"name":"david","age":14,"gender":"male"} This is python class class Person: def __init__(self): self.name = None self.age = None self.gener = None self.language = None this is Code #deserialize func~~~~~ print person.name #prints david print person.age #prints 14 print person.gender #prints male print person.language #prints "None" Can I deserialize Json to class in Python(like C# Newtonsoft) Thank you. 回答1: You can use it with the json.loads() method. You would also need to