JSONParse

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Who do I contact for help / questions?)
(Update Original's URL - Where's the code?)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
= JSONParse.js =  
 
= JSONParse.js =  
  
Looking for a C# solution? Try [[JSONObject]].
+
Use of this code is not recommended by its author. Try [[JSONObject]]. This page is here for purely historical reasons.
  
 
== Caveat ==
 
== Caveat ==
  
I (Tonio Loewald/podperson) reworked this code pretty extensively and it seems to work for me. I have not tested it extensively (yet) but it should be pretty easy to identify and fix any remaining errors as quite a bit of "voodoo" has been removed. It now runs well for me in iOS. Since I haven't tested my application yet, I'm leaving the warning in tact.
+
'''This software has known bugs. It does not seem to build for iOS and has not been tested on Unity 4. The author in fact recommends that you use [[JSONObject]], while JSONParse is being rewritten.'''
 
+
'''This software has known bugs. It does not seem to build for iOS and has not been tested on Unity 4. If you have problems with this script, please report them to the author and use [[JSONObject]] until the issue is fixed.'''
+
  
 
== What is it? ==
 
== What is it? ==
Line 14: Line 12:
  
 
== Wait, you had to port it? Why couldn't you just copy and paste, if it was in JavaScript? ==
 
== Wait, you had to port it? Why couldn't you just copy and paste, if it was in JavaScript? ==
It was in JavaScript, which is not the same thing as the language everyone on this forum pretends is JavaScript. That language is actually UnityScript. Real JavaScript sucks less.
+
 
 +
It was in JavaScript, which is not the same thing as the language everyone pretends is JavaScript. That language is actually UnityScript.
  
 
== Why not just use eval()? ==
 
== Why not just use eval()? ==
  
The problem with eval() as far as Unity goes is that it just translates your UnityScript into Boo then compiles it to the Mono CLR, as it does with the rest of your code before it can get run. As a result, eval() is really, really slow. So it's best to just parse it at runtime without having to compile.
+
First, it's really really slow.
  
Note: it's considered a REALLY BAD idea to use eval on JSON even aside from technical issues. It's a huge security hole and leaves you vulnerable to code-injection/man-in-the-middle attacks.
+
More importantly, it's a REALLY BAD idea to use eval on JSON received from an external source. It's a huge security hole and leaves you vulnerable to code-injection/man-in-the-middle attacks.
  
 
== Where's the code? ==
 
== Where's the code? ==
  
 +
Both of these versions are not recommended as the author is ashamed of the code quality that both are based on, and the original is no longer maintained (but is being superseded at the moment...)
 +
 +
The following is a re-working of the original so that the code compiles on iOS/Android/etc.:
 
https://github.com/tonioloewald/jsonparse
 
https://github.com/tonioloewald/jsonparse
  
I've linked this to an extensively modified version of the earlier code which compiles for mobile, has a convenient (strongly typed) wrapper object, and while lets you fairly conveniently create as well as consume JSON data.
+
:Note from the reworking author: I (Tonio Loewald/podperson) reworked this code pretty extensively and it seems to work for me. I have not tested it extensively (yet) but it should be pretty easy to identify and fix any remaining errors as quite a bit of "voodoo" has been removed. It now runs well for me in iOS. Since I haven't tested my application yet, I'm leaving the warning in tact.
 +
 
 +
: I've linked this to an extensively modified version of the earlier code which compiles for mobile, has a convenient (strongly typed) wrapper object, and while lets you fairly conveniently create as well as consume JSON data.
  
 
The original code is here:
 
The original code is here:
 
+
[https://github.com/philip-peterson/jsonparse Download from GitHub].
[https://github.com/ironmagma/jsonparse Download from GitHub].
+
  
 
== Who do I contact for help / questions? ==
 
== Who do I contact for help / questions? ==
 +
 +
[mailto:tloewald@gmail.com Tonio Loewald].
  
 
[mailto:ppeterson@ufl.edu Philip Peterson].
 
[mailto:ppeterson@ufl.edu Philip Peterson].
  
[mailto:tloewald@gmail.com Tonio Loewald].
+
[[Category:Utility]]
 +
[[Category:JSON]]

Latest revision as of 20:00, 7 January 2015

Contents

[edit] JSONParse.js

Use of this code is not recommended by its author. Try JSONObject. This page is here for purely historical reasons.

[edit] Caveat

This software has known bugs. It does not seem to build for iOS and has not been tested on Unity 4. The author in fact recommends that you use JSONObject, while JSONParse is being rewritten.

[edit] What is it?

It's a JSON parser written in UnityScript ("UnityJS"). A project I was working on needed one, and the only good existing one at the time of this writing is JSONObject, which (a) is written in C# (b) at the time did not take into account escaped characters within strings (it does now). So I ported Douglas Crockford's json_parse() function published in his book, JavaScript: The Good Parts.

[edit] Wait, you had to port it? Why couldn't you just copy and paste, if it was in JavaScript?

It was in JavaScript, which is not the same thing as the language everyone pretends is JavaScript. That language is actually UnityScript.

[edit] Why not just use eval()?

First, it's really really slow.

More importantly, it's a REALLY BAD idea to use eval on JSON received from an external source. It's a huge security hole and leaves you vulnerable to code-injection/man-in-the-middle attacks.

[edit] Where's the code?

Both of these versions are not recommended as the author is ashamed of the code quality that both are based on, and the original is no longer maintained (but is being superseded at the moment...)

The following is a re-working of the original so that the code compiles on iOS/Android/etc.: https://github.com/tonioloewald/jsonparse

Note from the reworking author: I (Tonio Loewald/podperson) reworked this code pretty extensively and it seems to work for me. I have not tested it extensively (yet) but it should be pretty easy to identify and fix any remaining errors as quite a bit of "voodoo" has been removed. It now runs well for me in iOS. Since I haven't tested my application yet, I'm leaving the warning in tact.
I've linked this to an extensively modified version of the earlier code which compiles for mobile, has a convenient (strongly typed) wrapper object, and while lets you fairly conveniently create as well as consume JSON data.

The original code is here: Download from GitHub.

[edit] Who do I contact for help / questions?

Tonio Loewald.

Philip Peterson.

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox