Skip to content

Commit 6083fee

Browse files
committed
Package and readme updates
1 parent 5db5cd7 commit 6083fee

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
</a>
77
</p>
88

9-
Package for creating packages!
9+
A C# json reader/writer which is Unity3D compatible based on http://wiki.unity3d.com/index.php/SimpleJSON
10+
The official Github repo for this script can be found at https://github.com/Bunny83/SimpleJSON/blob/master/SimpleJSON.cs
11+
Original improvements from https://github.com/HenrikPoulsen/SimpleJSON
12+
This repository is a fork that has been updated for direct import with the Unity PackageManager.
1013

1114
## Quick Package Install
1215

@@ -32,12 +35,41 @@ Find the manifest.json file in the Packages folder of your project and edit it t
3235
Changes between 'DOC START' and 'DOC END' will not be modified by readme update scripts
3336
-->
3437

35-
# SimpleJSON
36-
A C# json reader/writer which is Unity3D compatible based on http://wiki.unity3d.com/index.php/SimpleJSON
37-
38-
The official Github repo for this script can be found at https://github.com/Bunny83/SimpleJSON/blob/master/SimpleJSON.cs
39-
40-
This repository includes improvements that are mostly a bunch of unit tests (compatible with Unity test runner) which verify that things work like it should, and some performance improvements. The unit tests helped discover some stuff where this implemention did not follow the json standard and they were fixed.
38+
## Usage
39+
40+
```C#
41+
//From http://wiki.unity3d.com/index.php/SimpleJSON
42+
43+
var N = JSON.Parse(the_JSON_string);
44+
var versionString = N["version"].Value; // versionString will be a string containing "1.0"
45+
var versionNumber = N["version"].AsFloat; // versionNumber will be a float containing 1.0
46+
var name = N["data"]["sampleArray"][2]["name"];// name will be a string containing "sub object"
47+
48+
//C#
49+
string val = N["data"]["sampleArray"][0]; // val contains "string value"
50+
51+
//UnityScript
52+
var val : String = N["data"]["sampleArray"][0];// val contains "string value"
53+
54+
var i = N["data"]["sampleArray"][1].AsInt; // i will be an integer containing 5
55+
N["data"]["sampleArray"][1].AsInt = i+6; // the second value in sampleArray will contain "11"
56+
57+
N["additional"]["second"]["name"] = "FooBar"; // this will create a new object named "additional" in this object create another
58+
//object "second" in this object add a string variable "name"
59+
60+
var mCount = N["countries"]["germany"]["moronCount"].AsInt; // this will return 0 and create all the required objects and
61+
// initialize "moronCount" with 0.
62+
63+
if (N["wrong"] != null) // this won't execute the if-statement since "wrong" doesn't exist
64+
{}
65+
if (N["wrong"].AsInt == 0) // this will execute the if-statement and in addition add the "wrong" value.
66+
{}
67+
68+
N["data"]["sampleArray"][-1] = "Test"; // this will add another string to the end of the array
69+
N["data"]["sampleArray"][-1]["name"] = "FooBar"; // this will add another object to the end of the array which contains a string named "name"
70+
71+
N["data"] = "erased"; // this will replace the object stored in data with the string "erased"
72+
```
4173

4274
<!-- DOC-END -->
4375

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.gameframe.simplejson",
33
"version": "1.0.0",
44
"displayName": "SimpleJSON",
5-
"description": "Package for creating packages!",
5+
"description": "A C# json reader/writer which is Unity3D compatible based on http://wiki.unity3d.com/index.php/SimpleJSON\r\nThe official Github repo for this script can be found at https://github.com/Bunny83/SimpleJSON/blob/master/SimpleJSON.cs\r\nOriginal improvements from https://github.com/HenrikPoulsen/SimpleJSON\r\nThis repository is a fork that has been updated for direct import with the Unity PackageManager.",
66
"repositoryName": "SimpleJSON",
77
"author": {
88
"name": "Cory Leach",

0 commit comments

Comments
 (0)