How do I make JSON.NET ignore object relationships?

First, to address your issues with reference loops– The PreserveReferencesHandling setting controls whether Json.Net emits $id and $ref to track inter-object references. If you have this set to None and your object graph contains loops, then you will also need to set ReferenceLoopHandling to Ignore to prevent errors. Now, to get Json.Net to ignore all … Read more

how to return json error msg in asp.net web api?

A few points: If all you’re looking to do is return an error response containing a simple error message, Web API provides a CreateErrorResponse method for that. So you can simply do: return Request.CreateErrorResponse(HttpStatusCode.BadRequest, “An error just happened”); This will result in the following HTTP response (other headers omitted for brevity): HTTP/1.1 400 Bad Request … Read more

How to serialize byte[] as simple JSON Array and not as base64 in JSON.net?

JSON.NET is selecting the BinaryConverter to read and write an array of bytes. You can see in the source that it uses the WriteValue operation on the JsonWriter class with the array of bytes which causes them to be written to as Base-64. To modify this, you can write your own converter which reads and … Read more

Deserialize array of key value pairs using Json.NET

The simplest way is deserialize array of key-value pairs to IDictionary<string, string>: public class SomeData { public string Id { get; set; } public IEnumerable<IDictionary<string, string>> Data { get; set; } } private static void Main(string[] args) { var json = “{ \”id\”: \”123\”, \”data\”: [ { \”key1\”: \”val1\” }, { \”key2\” : \”val2\” } … Read more

How to serialize/deserialize a custom collection with additional properties using Json.Net

The problem is the following: when an object implements IEnumerable, JSON.net identifies it as an array of values and serializes it following the array Json syntax (that does not include properties), e.g. : [ {“FooProperty” : 123}, {“FooProperty” : 456}, {“FooProperty” : 789}] If you want to serialize it keeping the properties, you need to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)