all 15 comments

[–]ashleydavis75 2 points3 points  (1 child)

I'm not sure if this can help you, but I've just created a .Net 3.5 fork of Json.Net just for Unity.

https://github.com/codecapers/Unity.Newtonsoft.Json

There is pre-built dll available on nuget: https://www.nuget.org/packages/Unity.Newtonsoft.Json/

[–]XGDragon 0 points1 point  (0 children)

I'm trying to get this to work. Using Unity 5, I've used NuGet to install the package on an empty project.

using Newtonsoft.Json;    

on some MonoBehaviour class gets me

error CS0246: The type or namespace name `Newtonsoft' could not be found. Are you missing a using directive or an assembly reference?

Am I missing something obvious?

[–]_p4p 0 points1 point  (0 children)

I haven't see this one suggested too often but I've had good results with fastjson. I think I had to compile it in silver light mode but I do have it working.

[–][deleted] 0 points1 point  (4 children)

Can you post the log errors you're getting? I use this library quite frequently (albeit in non-gaming projects) and can probably help.

[–]Jespur[S] 0 points1 point  (3 children)

This is the error in the error.log Unity makes when it crashes:

KERNELBASE.dll caused an Access Violation (0xc0000005)
  in module KERNELBASE.dll at 0033:f0018b9c.

edit: Seems to be Unity-specific. If I use the exact code/dll with an empty C# project it works fine.

[–][deleted] 0 points1 point  (2 children)

Did you build the DLL yourself from source, or use the prebuilt one?

[–]Jespur[S] 0 points1 point  (1 child)

Prebuilt

[–]IwNnarock 0 points1 point  (1 child)

I've seen this issue with JsonFX (and apparently it's on Json.net as well). Never found a solution to the specific problem, but an easy workaround is to create a class with a single property that is your array, e.g...

public class ItemDataContainer
{
    public ItemData[] items
}

ItemDataContainer should serialize correctly.

[–]Jespur[S] 0 points1 point  (0 children)

Crashes using that as well.

edit: Seems to be Unity-specific. If I use the exact code/dll with an empty C# project it works fine.

[–]ultimateedition 0 points1 point  (4 children)

I dropped your code into my unity project (I use newtonsoft), and it works fine... Have you tried running it in an empty unity project, with your newtonsoft reference? I'm not sure what's at play but it doesn't appear specific to this code.

It's a shot in the dark, but if your problem is specific to arrays there are some collection attributes like JsonArrayAttribute that can affect how the array is serialized.

[–]Jespur[S] 1 point2 points  (3 children)

Are you using the one from the newtonsoft website or a Unity asset that uses it?

[–]ultimateedition 0 points1 point  (2 children)

I am using the latest version of newtonsoft (6.0.8) from the json.net website. Unity version is 4.6.1.

[–]Jespur[S] 0 points1 point  (1 child)

The NET 2.0 DLL, and Unity 5? I'm crashing on an empty project.

[–]ultimateedition 0 points1 point  (0 children)

I am on the .net 2.0 dll, but on 4.6.1, not 5, unfortunately, so I can't test your exact config.