Quantcast
Channel: Json.NET
Viewing all 1767 articles
Browse latest View live

New Post: Installation problem of JSON.NET in C++/CLI Windows Form Project with VS2010

$
0
0
I would like to use JSON.NET to do the JSON parsing process in my C++/CLI Windows Forms Application. The error occurred during the package installation of Newtonsoft.Json 5.0.5.
The installation log is as follows.
Installing 'Newtonsoft.Json 5.0.5'.
Successfully installed 'Newtonsoft.Json 5.0.5'.
Adding 'Newtonsoft.Json 5.0.5' to test.
Uninstalling 'Newtonsoft.Json 5.0.5'.
Successfully uninstalled 'Newtonsoft.Json 5.0.5'.
Install failed. Rolling back...
Install-Package : Could not install package 'Newtonsoft.Json 5.0.5'. You are trying to install this package
 into a project that targets 'Native,Version=v0.0', but the package does not contain any assembly reference
s or content files that are compatible with that framework. For more information, contact the package autho
r.
At line:1 char:16
+ Install-Package <<<<  Newtonsoft.Json
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageComman 
   d
Is it possible to use JSON.NET in C++/CLI language? Thank you.

Created Unassigned: Support Windows Phone 8 is needed [24323]

$
0
0
It currently only support Window Phone 7.1.

Could you please make it also support Windows Phone 8 ?

The following error comes from NuGet:

Successfully installed 'Newtonsoft.Json 5.0.5'.
Successfully uninstalled 'Newtonsoft.Json 5.0.5'.
Install failed. Rolling back...
Could not install package 'Newtonsoft.Json 5.0.5'. You are trying to install this package into a project that targets 'WindowsPhone,Version=v8.0', but the package does not contain any assembly references that are compatible with that framework. For more information, contact the package author.

Thanks.

Closed Unassigned: Support Windows Phone 8 is needed [24323]

$
0
0
It currently only support Window Phone 7.1.

Could you please make it also support Windows Phone 8 ?

The following error comes from NuGet:

Successfully installed 'Newtonsoft.Json 5.0.5'.
Successfully uninstalled 'Newtonsoft.Json 5.0.5'.
Install failed. Rolling back...
Could not install package 'Newtonsoft.Json 5.0.5'. You are trying to install this package into a project that targets 'WindowsPhone,Version=v8.0', but the package does not contain any assembly references that are compatible with that framework. For more information, contact the package author.

Thanks.
Comments: Log a bug with NuGet. There is a WP8 compatible portable class library that it should pick up.

Created Unassigned: Reference loop handling doesn't work, even with reference tracking on [24328]

$
0
0
Sometimes I get nulls in arbitrary places:

http://stackoverflow.com/questions/16472958/json-net-silently-ignores-circular-references-and-sets-arbitrary-links-in-the-ch

And sometimes I just get exceptions. I thought JSON.NET was supposed to support reference loops when I turned reference tracking on?

Commented Unassigned: Reference loop handling doesn't work, even with reference tracking on [24328]

$
0
0
Sometimes I get nulls in arbitrary places:

http://stackoverflow.com/questions/16472958/json-net-silently-ignores-circular-references-and-sets-arbitrary-links-in-the-ch

And sometimes I just get exceptions. I thought JSON.NET was supposed to support reference loops when I turned reference tracking on?
Comments: ** Comment from web user: JamesNK **

I need a simple repo.

Commented Unassigned: Reference loop handling doesn't work, even with reference tracking on [24328]

$
0
0
Sometimes I get nulls in arbitrary places:

http://stackoverflow.com/questions/16472958/json-net-silently-ignores-circular-references-and-sets-arbitrary-links-in-the-ch

And sometimes I just get exceptions. I thought JSON.NET was supposed to support reference loops when I turned reference tracking on?
Comments: ** Comment from web user: ekolis **

I assume you mean repro? I'll see what I can do...

Commented Unassigned: Reference loop handling doesn't work, even with reference tracking on [24328]

$
0
0
Sometimes I get nulls in arbitrary places:

http://stackoverflow.com/questions/16472958/json-net-silently-ignores-circular-references-and-sets-arbitrary-links-in-the-ch

And sometimes I just get exceptions. I thought JSON.NET was supposed to support reference loops when I turned reference tracking on?
Comments: ** Comment from web user: ekolis **

I have no idea what's going on. It works perfectly when I use a simplified version of my object graph, but when I use the actual code I'm working on, it breaks.

Commented Unassigned: Reference loop handling doesn't work, even with reference tracking on [24328]

$
0
0
Sometimes I get nulls in arbitrary places:

http://stackoverflow.com/questions/16472958/json-net-silently-ignores-circular-references-and-sets-arbitrary-links-in-the-ch

And sometimes I just get exceptions. I thought JSON.NET was supposed to support reference loops when I turned reference tracking on?
Comments: ** Comment from web user: ekolis **

Is there a limit to how deeply I can nest objects, perhaps? The loop only occurs after I'm already a few levels into the hierarchy.


Commented Unassigned: Reference loop handling doesn't work, even with reference tracking on [24328]

$
0
0
Sometimes I get nulls in arbitrary places:

http://stackoverflow.com/questions/16472958/json-net-silently-ignores-circular-references-and-sets-arbitrary-links-in-the-ch

And sometimes I just get exceptions. I thought JSON.NET was supposed to support reference loops when I turned reference tracking on?
Comments: ** Comment from web user: ekolis **

Oh, wait, it did serialize it! I was looking at the wrong file. I'm working on a strategy game, and I was looking at the player's view, which had some information taken out for fog of war purposes. The master game state file did have the properly serialized data. I guess the fog of war code removed the information I wanted from the player's view, even though it wasn't supposed to.

Commented Unassigned: Reference loop handling doesn't work, even with reference tracking on [24328]

$
0
0
Sometimes I get nulls in arbitrary places:

http://stackoverflow.com/questions/16472958/json-net-silently-ignores-circular-references-and-sets-arbitrary-links-in-the-ch

And sometimes I just get exceptions. I thought JSON.NET was supposed to support reference loops when I turned reference tracking on?
Comments: ** Comment from web user: ekolis **

Well, I was half mistaken there. It did *serialize* the game state correctly; it simply failed to *deserialize* it correctly. That mistaken data was then placed into the player view. (My code is currently set to test serialization by saving and loading the game before creating the player view.) Still no idea why the simplified object graph is deserializing properly and the full one isn't.

Created Unassigned: StringEnumConverter ignores [EnumMember] with [Flags] on enum [24329]

$
0
0
When the [Flags] attribute is applied to an enum, and the enum value to serialize is made up of more than one flag value, the StringEnumConverter fails to respect [EnumMemberAttribute].

code below is from a LINQPad snippet:

```
void Main()
{
List<Foo> lfoo = new List<Foo>() { Foo.FooBar, Foo.Bat, Foo.SerializeAsBaz, Foo.Bat | Foo.SerializeAsBaz, Foo.FooBar|Foo.SerializeAsBaz};
List<Bar> lbar = new List<Bar>() { Bar.FooBar, Bar.Bat, Bar.SerializeAsBaz };

lfoo.Dump();
Test("List<Foo> (bitmapped, string mapped with EnumMember)",lfoo);
lbar.Dump();
Test("List<Bar> (not bitmapped, string mapped with EnumMember)", lbar);

}

public static void Test<T>(string name, T ob)
{
var jstr = newtonSerialize(ob);

string.Format("Serialized {0}: {1}", name, jstr).Dump();

var new_list = JsonConvert.DeserializeObject<T>(jstr);
string.Format("Deserialize {0}:", name).Dump();
new_list.Dump();
}

public static string newtonSerialize(object ob)
{
var j = JsonSerializer.Create();
StringBuilder sb = new StringBuilder(256);
StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture);
using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Newtonsoft.Json.Formatting.Indented;
jsonWriter.QuoteName = false;
jsonWriter.QuoteChar = '\'';

j.Serialize(jsonWriter, ob);
}
return sw.ToString();
}

// Define other methods and classes here
[Flags]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
enum Foo {
[EnumMember(Value = "foo_bar")] FooBar = 0x01,
Bat = 0x02,
[EnumMember(Value ="baz")] SerializeAsBaz = 0x4,
};

[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
enum Bar {
[EnumMember(Value = "foo_bar")] FooBar,
Bat,
[EnumMember(Value ="baz")] SerializeAsBaz
};


```

Created Unassigned: Assembly Version Update? [24330]

$
0
0
Unsure if this is an actual issue: The current version (5.0.5) appears to be set as 4.5.0.0 in the assembly. Noticed this when attempting to resolve build warnings with another nuget package.

The following has worked for us, entirely unchanged since 4.5. Not sure if you want it updated.
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />

Created Unassigned: enum's [JsonConvert] annotation ignored when enum is Dictionary key [24331]

$
0
0
More trouble with enums! The converter is being ignored when the enum is a key in a dictionary. The code snippet below (A LINQPad snippet) should output:
```
{ 'baz': 'baz' }
```
but instead outputs:
```
{ 'SerializeAsBaz': 'baz' }
```

The enum is being correctly converted on the left-hand side, but not the right.

```
void Main()
{
var d = new Dictionary<Foo,object>();
d[Foo.SerializeAsBaz] = Foo.SerializeAsBaz;
newtonSerialize(d).Dump();
}

public static string newtonSerialize(object ob)
{
var j = JsonSerializer.Create();
StringBuilder sb = new StringBuilder(256);
StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture);
using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Newtonsoft.Json.Formatting.Indented;
jsonWriter.QuoteName = false;
jsonWriter.QuoteChar = '\'';

j.Serialize(jsonWriter, ob);
}
return sw.ToString();
}


// Define other methods and classes here
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
enum Foo {
[EnumMember(Value = "foo_bar")] FooBar = 0x01,
Bat = 0x02,
[EnumMember(Value ="baz")] SerializeAsBaz = 0x4,
};
```

New Post: missing Z on date conversion with default (iso I presume for .net 4.5 webapi

$
0
0
When I pass a datetime through webapi and it is converted to json, I get a date downloaded without a Z at the end. That is, this is what comes down:

{"data":[{"MessageString":"First Line","DateTimeRightNow":"2013-05-22T12:44:58.6763211-07:00","DateTime1PmOctober5Th2013":"2013-10-05T06:00:00-07:00"},

What am I missing to not get the Z?

Closed Unassigned: Assembly Version Update? [24330]

$
0
0
Unsure if this is an actual issue: The current version (5.0.5) appears to be set as 4.5.0.0 in the assembly. Noticed this when attempting to resolve build warnings with another nuget package.

The following has worked for us, entirely unchanged since 4.5. Not sure if you want it updated.
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
Comments: That's by design to help avoid bindingRedirects

Closed Issue: TypeConverter on Interfaces [24301]

$
0
0
In the current implementation of Json.NET, TypeConverters on interfaces and abstract classes are not handled properly (in my opinion). If such a converter exists on an interface, the following code fragment in the ConvertUtils.Convert(object initialValue, CultureInfo culture, Type targetType) method will throw an exception:

(lines 410ff)
if (targetType.IsInterface() || targetType.IsGenericTypeDefinition() || targetType.IsAbstract())
throw new ArgumentException("Target type {0} is not a value type or a non-abstract class.".FormatWith(CultureInfo.InvariantCulture, targetType), "targetType");


But in the next lines, the correct handling of the existing type converter takes place. So I would suggest to remove the above lines from the code. This does not break any unit tests and works (at least in my scenario it worked perfectly).

The case where no type converter is placed on an interface/abstract class is handled at the very end of the method.
Comments: I have fixed the issue with interfaces not deserializing when there is a valid type converter. I haven't added your change to deserialize using a type converter because there is a perf hit looking for a type converter and overriding ToString is simple.

Closed Unassigned: Reference loop handling doesn't work, even with reference tracking on [24328]

$
0
0
Sometimes I get nulls in arbitrary places:

http://stackoverflow.com/questions/16472958/json-net-silently-ignores-circular-references-and-sets-arbitrary-links-in-the-ch

And sometimes I just get exceptions. I thought JSON.NET was supposed to support reference loops when I turned reference tracking on?
Comments: Derp

Closed Unassigned: [Win2003 & Newtonsoft.Json.dll (.NET2.0version)]Build issue! [24316]

$
0
0
When build in VS there is a exception occurs which is as following:
Missing compiler required member 'System.Runtime.CompilerServices.ExtensionAttribute..ctor'

Could you please explain what's the reason of this issue? And please help me to resolve this issue~
If you can not resolve this issue please let me know ASAP, Thx a lot :)
Comments: I don't know. Works on my machine(tm)

Closed Unassigned: enum's [JsonConvert] annotation ignored when enum is Dictionary key [24331]

$
0
0
More trouble with enums! The converter is being ignored when the enum is a key in a dictionary. The code snippet below (A LINQPad snippet) should output:
```
{ 'baz': 'baz' }
```
but instead outputs:
```
{ 'SerializeAsBaz': 'baz' }
```

The enum is being correctly converted on the left-hand side, but not the right.

```
void Main()
{
var d = new Dictionary<Foo,object>();
d[Foo.SerializeAsBaz] = Foo.SerializeAsBaz;
newtonSerialize(d).Dump();
}

public static string newtonSerialize(object ob)
{
var j = JsonSerializer.Create();
StringBuilder sb = new StringBuilder(256);
StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture);
using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Newtonsoft.Json.Formatting.Indented;
jsonWriter.QuoteName = false;
jsonWriter.QuoteChar = '\'';

j.Serialize(jsonWriter, ob);
}
return sw.ToString();
}


// Define other methods and classes here
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
enum Foo {
[EnumMember(Value = "foo_bar")] FooBar = 0x01,
Bat = 0x02,
[EnumMember(Value ="baz")] SerializeAsBaz = 0x4,
};
```

Closed Unassigned: StringEnumConverter ignores [EnumMember] with [Flags] on enum [24329]

$
0
0
When the [Flags] attribute is applied to an enum, and the enum value to serialize is made up of more than one flag value, the StringEnumConverter fails to respect [EnumMemberAttribute].

code below is from a LINQPad snippet:

```
void Main()
{
List<Foo> lfoo = new List<Foo>() { Foo.FooBar, Foo.Bat, Foo.SerializeAsBaz, Foo.Bat | Foo.SerializeAsBaz, Foo.FooBar|Foo.SerializeAsBaz};
List<Bar> lbar = new List<Bar>() { Bar.FooBar, Bar.Bat, Bar.SerializeAsBaz };

lfoo.Dump();
Test("List<Foo> (bitmapped, string mapped with EnumMember)",lfoo);
lbar.Dump();
Test("List<Bar> (not bitmapped, string mapped with EnumMember)", lbar);

}

public static void Test<T>(string name, T ob)
{
var jstr = newtonSerialize(ob);

string.Format("Serialized {0}: {1}", name, jstr).Dump();

var new_list = JsonConvert.DeserializeObject<T>(jstr);
string.Format("Deserialize {0}:", name).Dump();
new_list.Dump();
}

public static string newtonSerialize(object ob)
{
var j = JsonSerializer.Create();
StringBuilder sb = new StringBuilder(256);
StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture);
using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Newtonsoft.Json.Formatting.Indented;
jsonWriter.QuoteName = false;
jsonWriter.QuoteChar = '\'';

j.Serialize(jsonWriter, ob);
}
return sw.ToString();
}

// Define other methods and classes here
[Flags]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
enum Foo {
[EnumMember(Value = "foo_bar")] FooBar = 0x01,
Bat = 0x02,
[EnumMember(Value ="baz")] SerializeAsBaz = 0x4,
};

[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
enum Bar {
[EnumMember(Value = "foo_bar")] FooBar,
Bat,
[EnumMember(Value ="baz")] SerializeAsBaz
};


```
Viewing all 1767 articles
Browse latest View live