Forum C# JSON with C# and PlayerIO :(

JSON with C# and PlayerIO :(

Postby mulatto401 » August 17th, 2010, 11:19 pm

Hi All,

I been trying to Decode JSON from my server that PlayerIO requests from using the Web feature, but I can't seem to import System.Web.Script.Serialization; or use any outside DLL that provides great JSON support.

Does anyone know a way to get JSON working in C# with PlayerIO??

Thanks
mulatto401
Paid Member
 
Posts: 34
Joined: June 13th, 2010, 11:13 pm

Re: JSON with C# and PlayerIO :(

Postby Oliver » August 19th, 2010, 10:34 am

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
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: JSON with C# and PlayerIO :(

Postby mulatto401 » August 23rd, 2010, 12:49 am

Hi,

I spent a few hours just attempting to write my own parser and I have 1 working, its not too bad. It just handles 1 object (not objects inside other objects).

It works for what I need it to do, if anyone needs something like this for the meantime feel free to use it

Code: Select all
// 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;
        }
mulatto401
Paid Member
 
Posts: 34
Joined: June 13th, 2010, 11:13 pm

Re: JSON with C# and PlayerIO :(

Postby 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


Has there been any update on this topic. I'd live to be able to work with json object. specifically when sending complex items to the client. I've been trying to use other formats but all seem to have their drawbacks. csv is fragile and doesn't support hierarchy very easily.. and xml is triple the bandwidth.. i have objects with nested object arrays. even if i could Send DatabaseObjects to the Player from server this would be a great help. Let me know if you have any solution or ideas for this.

thanks.
iksnae
 
Posts: 9
Joined: August 6th, 2010, 4:59 am

Re: JSON with C# and PlayerIO :(

Postby Oliver » January 10th, 2011, 2:42 pm

Hey,

No -- there haven't been any updates on this issue. I do like your suggestion of letting clients and servers exchange database-like objects...

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: JSON with C# and PlayerIO :(

Postby iksnae » January 10th, 2011, 4:46 pm

thanks for the update..
in the meantime, i'm generating xml strings and sending them to the client as the first argument in a message.. this is OK as far as getting the data to the client, the problem to overcome next is sending the data back from the client to server.. Since I can't use the built-in C# xml parsing options, I'll have to build a C# parser to process the message from client.

Exchanging the DatabaseObjects between the two would be ideal though. it would cut overhead of parsing the xml, shave bandwidth dramatically and also simplify development. I hope that this becomes an option in future updates.

BTW.. Great job on the last update!
iksnae
 
Posts: 9
Joined: August 6th, 2010, 4:59 am

Re: JSON with C# and PlayerIO :(

Postby tef » February 28th, 2011, 5:31 pm

I must say I am stunned that PlayerIO doesn't allow serialization of Json. :shock:

I usually use: http://pietschsoft.com/post/2008/02/NET ... lizer.aspx

We are trying to implement scripting for all models/units/effects in the game. I must say I am very dissapointed that it isn't allowed yet. :(

What is the recommended way to script on PlayerIO, now that json isn't an option anymore. But it seem kind of stupid to invent your own scripting language when Json is used everywhere and is already in the .NET 3.5 framework.
tef
 
Posts: 10
Joined: January 7th, 2011, 3:38 pm

Re: JSON with C# and PlayerIO :(

Postby tef » March 1st, 2011, 12:04 pm

Hey again...

I just took a JSON decoder/encoder and fixed it to work with PlayerIO's restrictions. Mainly replacing the use of "ref" with a wrapper class.

replaced.
ref int index, ref bool success


with.
Code: Select all
public class IndexAndSuccess
{
        public int index = 0;
        public bool success = false;
}


removed.
static functions

The original code can be found here: http://techblog.procurios.nl/k/news/vie ... -JSON.html
Attachments
JSON.zip
JSON decoder/encoder
(2.92 KiB) Downloaded 27488 times
tef
 
Posts: 10
Joined: January 7th, 2011, 3:38 pm

Re: JSON with C# and PlayerIO :(

Postby eXpressionist » March 2nd, 2011, 8:25 am

Please, any example of use. Like I'm gonna send request on php script and receive a response in json from it.
In Soviet Russia PlayerIO plays you

I'm just a newbie here, don't hit me hard, plz =)
eXpressionist
 
Posts: 9
Joined: January 27th, 2011, 9:55 am
Location: Russia, Nalchik

Re: JSON with C# and PlayerIO :(

Postby FulaFisken » March 2nd, 2011, 10:34 am

I am using it to get information from json files, but this can ofcourse be sent to the server as well.

Code: Select all
game.PlayerIO.Web.Get(url, delegate(HttpResponse response)
{
       JSON jsonHelper = new JSON();
       object json = jsonHelper.JsonDecode(response.Text);
}


Json:
Code: Select all
string jsonString = '[{"name":"Johan", "age":18},{"name":"Mike","age":20}]';


How to use:
Code: Select all
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"]);
}


Edit: tef == FulaFisken :) Just my compnies account
Fula Fisken
website blog twitter
Play Game
Astroflux
User avatar
FulaFisken
Paid Member
 
Posts: 139
Joined: March 2nd, 2011, 10:15 am

Re: JSON with C# and PlayerIO :(

Postby jasonMcIntosh » June 11th, 2011, 8:54 pm

Ohmygoodness. I just want to have initialization data available to my server on startup, but I can't use XML and looks like I can't use JSON, either. These are standard tools for data driven design.

Please, please, very pretty please, can we have one or both whitelisted ASAP?
Jason McIntosh
Otherwhere Gameworks
jasonMcIntosh
 
Posts: 81
Joined: February 25th, 2011, 4:51 am

Re: JSON with C# and PlayerIO :(

Postby trycatchgames » June 19th, 2011, 3:45 am

Bumping this thread. We need JSON support. And if it is supported, please note it on this thread. I shouldn't have to dig around with separate code libraries for something this standard.
trycatchgames
 
Posts: 21
Joined: March 25th, 2011, 2:39 am

Re: JSON with C# and PlayerIO :(

Postby Vania » June 30th, 2011, 10:45 pm

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#?
Vania
 
Posts: 198
Joined: March 24th, 2010, 9:01 pm

Re: JSON with C# and PlayerIO :(

Postby 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#?


I am Tef :D

If you upload the json to GameFS or a any other hosting site you can just do a http request and download it from there upon starting a room. Thats what I did. What are you using json for btw?
Fula Fisken
website blog twitter
Play Game
Astroflux
User avatar
FulaFisken
Paid Member
 
Posts: 139
Joined: March 2nd, 2011, 10:15 am

Re: JSON with C# and PlayerIO :(

Postby Vania » July 1st, 2011, 1:15 am

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...
Vania
 
Posts: 198
Joined: March 24th, 2010, 9:01 pm

Re: JSON with C# and PlayerIO :(

Postby 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...


Ok. But why are you not using the BigDB to store that information instead? Or do you have an external editor that creates json and you rather not deviate from that? I actually abandoned json and just built my game editor around the a Database interface that handled the BigDB api.
Fula Fisken
website blog twitter
Play Game
Astroflux
User avatar
FulaFisken
Paid Member
 
Posts: 139
Joined: March 2nd, 2011, 10:15 am

Re: JSON with C# and PlayerIO :(

Postby Vania » July 1st, 2011, 4:01 pm

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.
Vania
 
Posts: 198
Joined: March 24th, 2010, 9:01 pm

Re: JSON with C# and PlayerIO :(

Postby 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.


Thanks for answering. I guess we might do that once we have more traffic.
Fula Fisken
website blog twitter
Play Game
Astroflux
User avatar
FulaFisken
Paid Member
 
Posts: 139
Joined: March 2nd, 2011, 10:15 am

Re: JSON with C# and PlayerIO :(

Postby bohdan » August 8th, 2011, 11:10 pm

Hi, I just wanted to bump this thread again. I'd like to see JSON support as well.
bohdan
 
Posts: 30
Joined: June 24th, 2011, 8:18 am

Re: JSON with C# and PlayerIO :(

Postby Vania » August 9th, 2011, 3:37 am

Have you tried using tef's code?

It works well for me. The only thing I had to add to his code was a base64 type.
Vania
 
Posts: 198
Joined: March 24th, 2010, 9:01 pm

Re: JSON with C# and PlayerIO :(

Postby bohdan » August 9th, 2011, 11:24 pm

Hey Vania,

I haven't tried the code. I'm planning on integrating a Bing custom search engine, which uses JSON. But, I'm far from implementing it. It looks like there may be a workaround, but I don't know. I'm new to C# and server development. So I thought it'd be a good idea to put in my support for JSON so I have to do as little hacking as possible.
bohdan
 
Posts: 30
Joined: June 24th, 2011, 8:18 am

Re: JSON with C# and PlayerIO :(

Postby fex » October 22nd, 2012, 8:30 pm

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.
fex
Paid Member
 
Posts: 12
Joined: January 10th, 2012, 1:21 am

Re: JSON with C# and PlayerIO :(

Postby 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.


You can use basic XML parsing, see the last entry at multiplayer/xml-t1685
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark


Return to C#



cron