by mulatto401 » August 17th, 2010, 11:19 pm
by Oliver » August 19th, 2010, 10:34 am
by mulatto401 » August 23rd, 2010, 12:49 am
// Quick 1 object parsing, does not parse objects inside objects
private Hashtable JSON(String str)
{
char[] letters = str.ToCharArray();
Hashtable main = new Hashtable();
Boolean inName = false;
Boolean inValue = false;
String currentName = "";
String currentValue = "";
for (int i = 0; i < letters.Length-1; i++)
{
// switching from Name/Value
if(letters[i] == '"'){
if(!inName && !inValue && currentName == "") {
inName = true;
inValue = false;
}
else if(inName && !inValue)
inName = false;
else if(inValue && !inName && currentValue != "") {
inValue = false;
main.Add(currentName, currentValue);
currentName = "";
currentValue = "";
}
}
else if (letters[i] == ':')
{
inName = false;
inValue = true;
}
else if (letters[i] == ',')
{
inValue = false;
main.Add(currentName, currentValue);
currentName = "";
currentValue = "";
}
// Adding name/value
else if (letters[i] != '{' && letters[i] != '}')
{
if (letters[i] == ' ' && !inName && !inValue)
continue;
else if (inName)
currentName += letters[i];
else
currentValue += letters[i];
}
}
return main;
}
by iksnae » January 9th, 2011, 10:57 am
Oliver wrote:Hey,
Uhm.... I don't know if there is a good reason to disallow JSON. It's just not a part of the whitelist yet. I'll put it on the todo list to get somebody to evaluate if it should go into the whitelist (i.e, if there are any security issues with it).
Since this won't be fixed RIGHT NOW, a work around could be to simply send the the data back from your webserver in some text format you can easily parse.
Might i ask what kind of data your sending back and forth? How complex is the data structures?
Best,
Oliver
by Oliver » January 10th, 2011, 2:42 pm
by iksnae » January 10th, 2011, 4:46 pm
by tef » February 28th, 2011, 5:31 pm
by tef » March 1st, 2011, 12:04 pm
ref int index, ref bool success
public class IndexAndSuccess
{
public int index = 0;
public bool success = false;
}
by eXpressionist » March 2nd, 2011, 8:25 am
by FulaFisken » March 2nd, 2011, 10:34 am
game.PlayerIO.Web.Get(url, delegate(HttpResponse response)
{
JSON jsonHelper = new JSON();
object json = jsonHelper.JsonDecode(response.Text);
}
string jsonString = '[{"name":"Johan", "age":18},{"name":"Mike","age":20}]';
JSON jsonHelper = new JSON();
ArrayList people = (ArrayList)jsonHelper.JsonDecode(jsonString);
foreach (Hashtable p in people)
{
string name = (string)p["name"];
int age = Convert.toInt32(p["age"]);
}
by jasonMcIntosh » June 11th, 2011, 8:54 pm
by trycatchgames » June 19th, 2011, 3:45 am
by Vania » June 30th, 2011, 10:45 pm
by FulaFisken » July 1st, 2011, 12:52 am
Vania wrote:I just took the Jason parser posted by tef, it's exactly what I needed.
The problem now is I cannot embed the JSON text file as a resource in C# because Properties.Resources has some disallowed types. Any other way of embedding a file for use in C#?
by Vania » July 1st, 2011, 1:15 am
by FulaFisken » July 1st, 2011, 11:00 am
Vania wrote:Hi Tef, thanks for your answer.
I found the solution to my problem, there's a playerio class called EmbeddedRessource that lets you access embedded files.
I'm using JSON for some data that must be the same in the client and the server, the stats for the units, terrain, weapons...
by Vania » July 1st, 2011, 4:01 pm
Ok. But why are you not using the BigDB to store that information instead?
by FulaFisken » July 1st, 2011, 4:17 pm
Vania wrote:Ok. But why are you not using the BigDB to store that information instead?
I was, but I'm optimizing. I save a lot of traffic by embedding that info directly in the client and server instead of retrieving it from the database everytime. I'm still using BigDB for thing like levels and such.
by bohdan » August 8th, 2011, 11:10 pm
by Vania » August 9th, 2011, 3:37 am
by bohdan » August 9th, 2011, 11:24 pm
by fex » October 22nd, 2012, 8:30 pm
by Benjaminsen » October 23rd, 2012, 11:23 am
fex wrote:Has anyone had time to modify this code for nested objects/arrays?
Since XML still isn't whitelisted, I'm planning on manually converting everything to JSON, then using this hack to read it in on room launch. Unfortunately, it doesn't look like this hack allows nested objects/arrays: it's basically just a shallow key:value parser.