Created
January 8, 2016 03:15
-
-
Save grimmdev/e6171483ae825360c97f to your computer and use it in GitHub Desktop.
Extra and useful JSON Functions for SimpleJSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
using SimpleJSON; | |
public class JSONExtras { | |
public int[] ToIntArray(string n) { | |
var j = JSON.Parse(n); | |
int[] a = new int[j.Count]; | |
for(int i = 0; i < j.Count; i++) | |
{ | |
a[i] = j[i].AsInt; | |
} | |
return a; | |
} | |
public float[] ToFloatArray(string n) { | |
var j = JSON.Parse(n); | |
float[] a = new float[j.Count]; | |
for(int i = 0; i < j.Count; i++) | |
{ | |
a[i] = j[i].AsFloat; | |
} | |
return a; | |
} | |
public bool[] ToBoolArray(string n) { | |
var j = JSON.Parse(n); | |
bool[] a = new bool[j.Count]; | |
for(int i = 0; i < j.Count; i++) | |
{ | |
a[i] = j[i].AsBool; | |
} | |
return a; | |
} | |
public string[] ToStringArray(string n) { | |
var j = JSON.Parse(n); | |
string[] a = new string[j.Count]; | |
for(int i = 0; i < j.Count; i++) | |
{ | |
a[i] = j[i].ToString(); | |
} | |
return a; | |
} | |
public List<int> ToIntList(string n) { | |
var j = JSON.Parse(n); | |
List<int> a = new List<int> (); | |
for(int i = 0; i < j.Count; i++) | |
{ | |
a.Add(j[i].AsInt); | |
} | |
return a; | |
} | |
public List<float> ToFloatList(string n) { | |
var j = JSON.Parse(n); | |
List<float> a = new List<float> (); | |
for(int i = 0; i < j.Count; i++) | |
{ | |
a.Add(j[i].AsFloat); | |
} | |
return a; | |
} | |
public List<bool> ToBoolList(string n) { | |
var j = JSON.Parse(n); | |
List<bool> a = new List<bool> (); | |
for(int i = 0; i < j.Count; i++) | |
{ | |
a.Add(j[i].AsBool); | |
} | |
return a; | |
} | |
public List<string> ToStringList(string n) { | |
var j = JSON.Parse(n); | |
List<string> a = new List<string> (); | |
for(int i = 0; i < j.Count; i++) | |
{ | |
a.Add(j[i].ToString()); | |
} | |
return a; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment