How do I use JSON

Get help using Construct 2

Post » Tue Oct 20, 2015 8:56 am

Hi all,

I'd like to use the JSON format as easily as in programming code.
Is that possible in C2 to use JSON as easily ? without using dictionnaries or arrays ?

For example, a JSON variable like :
myVar = {"pseudo" : "Adisma", "level" : 8}
And use it as :

myVar.pseudo
myVar.level

I didn't find any plugin allowing this..

Thanks in advance :)
B
6
S
1
Posts: 45
Reputation: 509

Post » Tue Oct 20, 2015 12:02 pm

You can use Token At, and then you can do any kind of "Code" you want. Can use .Json, or just make a psudo code.

Just use an array, Dictionary , or an object with instance variables and save and load as Json. This is the easiest for most people.

The Token At is the Most like real programming. It is Cryptic, and hard to read, and hard to edit. It take special knowledge to use it, and most people will not understand it at first. It is easy to make typos, and takes special loops to actually read and use. Perfect for programmers!

So basically If you want it "easy as" Construct 2, then simply use an array or a dictionary, or use instance variables. Then simply save and load as json.

Or if you want to over complicate things, and make it "easy as in programming" then Token count and Token At is your best solution.

You can even over complicate things with XML if you want it really easy.

I am still waiting for someone to do a plugin for this:
https://goo.gl/vfgFK7
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Tue Oct 20, 2015 12:49 pm

Doing something a different way from what you are used to doesn't make it harder..
Learning new ways to do things are an essential part of programming..
Instead of calling it "asking for the easy way", some people would call it "asking for the lazy way"..
(Not that I'm that kind of a person, offcourse)

I think this plugin might suit you:

Plugin json
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Oct 20, 2015 1:19 pm

LittleStain wrote:Doing something a different way from what you are used to doesn't make it harder.


Totally agree. Learning the C2 way of doing things just take a little extra effort. In cases like this it will be much faster than using Plugin or having to extensively use Token At and token count to retrieve things.

You can simply retrieve a value from an array, you do not need to bog down the CPU with Token at, Dictionary or loops. You dont need a plugin that may cause incompatibility problems in the future.

By simply learning the C2 way of doing things, it is not only easier to debug, it is also much faster then re-inventing the wheel. Not to mention it is safer, and you dont have to bloat your application with a bunch of json files.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Tue Oct 20, 2015 2:56 pm

LittleStain wrote:Doing something a different way from what you are used to doesn't make it harder..
Learning new ways to do things are an essential part of programming..
Instead of calling it "asking for the easy way", some people would call it "asking for the lazy way"..
(Not that I'm that kind of a person, offcourse)

I think this plugin might suit you:

Plugin json


It should :)
I will try it.

Moreover, I'll try the Hash Table plugin from rex that might help too..

I'll try both and use the best for my use (e.g. using JSON coming from AJAX request).

Thanks all of you..
B
6
S
1
Posts: 45
Reputation: 509

Post » Tue Oct 20, 2015 4:40 pm

Glad I could help..

I should warn you, though, that using those plugins might really diminish the amount of help you are able to get on the forums..
People who don't have them installed can't open your project and will have no clue as to how to work eith them anyway..

Good luck on your project!
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests