Parsing JSON DateTime from Newtonsoft’s JSON Serializer

Use one of the JsonConverters that come with Json.NET for working with dates to get a better format. JavaScriptDateTimeConverter will automatically give you a JavaScript date. public class LogEntry { public string Details { get; set; } public DateTime LogDate { get; set; } } [Test] public void WriteJsonDates() { LogEntry entry = new LogEntry … Read more

jQuery AJAX request failing in IE

Fixed, I changed the content-type from application/json; charset=utf8 to just plain application/json. I hate IE 🙂 Also to avoid IE super-caching try this: var d = new Date(); $.ajax({ url:”{{SITE_URL}}/content/twitter.json?_=”+d.getTime(), …Snip… That way each request is a new url for IE to get 😀

How can I decode JWT (JSON web token) token in Swift?

If you are okay with using a library i would suggest this and then import the library import JWTDecode and execute. let jwt = try decode(jwt: token) Since you didn’t want to include this library i brought out the needed parts to make it work. func decode(jwtToken jwt: String) -> [String: Any] { let … Read more

How to convert JSON text into objects using C# [duplicate]

To create a class off a json string, copy the string. In Visual Studio, in the menu at the top, click Edit > Paste special > Paste Json as classes. Install Newtonsoft.Json via Nuget Paste the following code into your project, “jsonString” being the variable you want to deserialize : Rootobject r = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(jsonString); Don’t … Read more

gson invoking standard deserialization in custom deserializer

You can do that by implementing custom TypeAdapterFactory for your object (say CustomClass.class) to be deserialized as below. public class CustomTypeAdapterFactory implements TypeAdapterFactory { public final TypeAdapter create(Gson gson, TypeToken type) { return new TypeAdapter() { @Override public void write(JsonWriter out, Object value) throws IOException { JsonElement tree = delegate.toJsonTree(value); //add code for writing object … Read more