Doesn't the title make you excited?! (lol)
I'm working on a JSON(esque) parser that I intend to use for something kinda-sorta Quake related, in the future. For those that are not aware, here is an example of JSON.
It's nothing more than xml written in object format. You would access values with dot syntax - players.playerOne.name - returns freddy55. Simple stuff. Flash already has a JSON parser, but as I said - I am making a JSON(esque) parser, so I needed to write my own in order to handle the new syntax/possibilities.
This means that I am just feeding flash a string and I need to explain to it how to loop through delimiters and gather information. This posed an immediate puzzle - How do I get the proper delimiters.
For instance "players" is the root parent object, so I need the first and last delimiters, BUT there are a lot of identical close delimiters between. I solved this problem and the below screenshot is my heavily commented code.
I'm hoping this post can serve one or more of any of the following possibilities.
1) my code is right on and others can duplicate it in their language of choice, should they need such a script
2) someone else that has done this before, knows a better way and is inclined to share it (in full - i don't care what language, functions/loops/etc are pretty universal)
3) someone will post a truck (actually I just threw this one in)

edit: one hole that needs to be closed is the last else{}. Technically match and count could be off and it would still act like a success. A check needs to be made and if it fails it needs to display a "script error". The only situation where this could happen, is if the programmer didn't properly close/end something.
I used a screenshot because the syntax hilighting makes it easier to read and understand, but if commented code is still too confusing, here is a walk-through, using an object that is stripped down to it's delimiters.
:{
____:{
________:{
________};
____};
____:{
____};
};
find :{ - result: :{
find }; from :{ - result: };
count :{ between :{ and }; - result: count = 2
start at }; and find }; - result: };
find :{ between }; and }; - result none - match+1=1
start at }; and find }; - result: };
find :{ between }; and }; - result 1 - match+0=1
start at }; and find }; - result: };
find :{ between }; and }; - result none - match+1=2
match = count and we have the proper delimiter
I'm working on a JSON(esque) parser that I intend to use for something kinda-sorta Quake related, in the future. For those that are not aware, here is an example of JSON.
Code:
players:{ playerOne:{ name:freddy55, score:200, health:80, gun:M4A1 }, playerTwo:{ name:StoneY58, score:160, health:100, gun:AK47 }, }
This means that I am just feeding flash a string and I need to explain to it how to loop through delimiters and gather information. This posed an immediate puzzle - How do I get the proper delimiters.
For instance "players" is the root parent object, so I need the first and last delimiters, BUT there are a lot of identical close delimiters between. I solved this problem and the below screenshot is my heavily commented code.
I'm hoping this post can serve one or more of any of the following possibilities.
1) my code is right on and others can duplicate it in their language of choice, should they need such a script
2) someone else that has done this before, knows a better way and is inclined to share it (in full - i don't care what language, functions/loops/etc are pretty universal)
3) someone will post a truck (actually I just threw this one in)

edit: one hole that needs to be closed is the last else{}. Technically match and count could be off and it would still act like a success. A check needs to be made and if it fails it needs to display a "script error". The only situation where this could happen, is if the programmer didn't properly close/end something.
I used a screenshot because the syntax hilighting makes it easier to read and understand, but if commented code is still too confusing, here is a walk-through, using an object that is stripped down to it's delimiters.
:{
____:{
________:{
________};
____};
____:{
____};
};
find :{ - result: :{
find }; from :{ - result: };
count :{ between :{ and }; - result: count = 2
start at }; and find }; - result: };
find :{ between }; and }; - result none - match+1=1
start at }; and find }; - result: };
find :{ between }; and }; - result 1 - match+0=1
start at }; and find }; - result: };
find :{ between }; and }; - result none - match+1=2
match = count and we have the proper delimiter
Comment