Can anyone recommend a C# library for reading JSON. The one I have been using uses System.Data which you can’t use in Unity iPhone.
In the absence of any JSON support, what is the best way to retrieve remote data? Is the only option to publish as XML and retrieve that, or is there something else I have missed?
I’d be interested too in that. So far I’m using simple key/value pairs that I’m returning from my webserver delimited by newlines or alike characters. Plain old boring parsing. But JSON would be cool to have it, esp. with usage of rest services.
If you have iPhone Advanced, the simple and performant solution likely would be usage of the available possibilities on the iPhone itself by using the JSON 2.0+ framework for Obj C directly.
This is naturally possible with iPhone Basic too but that would mean parsing twice or very slow step by step reading through the playerprefs which isn’t very efficient.
Look into Json.NET at
Json.NET - Newtonsoft
The current version may not run with Unity’s version of Mono. But, you may be able to find an older version of the library that will.
that pretty surely will not work at all.
Unity iPhone is restricted to .NET 1.1 and the features there even include LINQ and XML, with XML beeing unavailable to iPhone Basic (due to runtime size restrictions against the iphone sdk reqs)
I’ve ended up using XML for now. It’s a bit tedious after using JSON though. I will have a look at utilising the Obj C native classes next time. Has anyone got much experience working this way? How difficult is it to get these classes working alongside Unity?
If you have been using this one:
http://techblog.procurios.nl/k/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
removing the dependency on System.Data is straightforward. Delete the line “import System.Data” and the parser functions just fine :P.
I recall some problems with the Unicode stuff on the iPhone, but commenting out the unicode escape (\u) code, will leave you a JSON parser that works fine (except that it won’t work with unicode characters, obviously).
I got into some JSON work yesterday and tried two C# plugins from json.org.
“JSON for .NET.” - doesn’t support nested objects and is not in active development afaik.
Jayrock worked well for me: http://jayrock.berlios.de/