#Could you be able to dm me or to create

1 messages · Page 1 of 1 (latest)

runic egret
#

Just use a thread.

faint night
#

Perfect

#

Ok, correct me if i'm wrong

#

A JSON always is between two {} and in this case there are 4:

#

two for results

#

nono, i'm wrong

#

cause there are more

#

i dont get why there are two JSON...

blissful shoal
#

Because one object contains the other

runic egret
#

It is made up two major components

#

objects and arrays

severe crest
runic egret
#

An object is wrapped in { curly braces }. It is made up of name-value pairs.

#

{ "foo": 1, "bar": 2 }

#

This has two name-value pairs: "foo" and 1. "bar" and 2.

#

An array is wrapped in [ square brackets ]

faint night
#

and why does satatus doesn't have curly braces?

runic egret
#

Because its value is neither an object nor an array.

#

It is a simple value.

#

A string value, to be specific.

blissful shoal
# faint night cause there are more

they probably structured it this way so they could do this:

{
  "results" : {
    // a bunch of data
  },
  "status" : "success"
}```
or
```json
{
  "results" :  null,
  "status" : "error"
}```
runic egret
#

You're putting a lot of emphasis on the existence of "curly braces" here

blissful shoal
#

but it doesn;t relaly matter why it's just how they chose to structure it

runic egret
#

you shouldn't be thinking "JSON is when braces"

#

They are simply how you denote an object.

#

You don't just add lots of curly braces everywhere to make it JSON or something

#

If I serialize a List<int>, it'll look like this in JSON:

#
[1, 2, 3, 4, 5]
#

If I serialize an int, I'd get...

5
#

literally just 5

blissful shoal
#

Yep! JSON basically has 4 datatypes:

  • numbers which look like 5.332
  • strings which look like "example"
  • objects which look like:
{
  // any data you want in here
}```
- arrays which look like:
```json
[1, 3, 5, 2, 6]```
#

and every piece of data has a name
so in this case you have "results" which is an object and "status" which is a string

runic egret
#

Objects and arrays are what allow you to store something more complex than a single value.

#

You almost always are, hence why you almost always see { curly braces } and [ square brackets ]

runic egret
#

the entire spec is extremely short

blissful shoal
#

true

runic egret
#

I think it will help you to get a mental model.

faint night
runic egret
#

Nowhere

#

Just make them up

#

Make a class that holds an int. Serialize it

#

Then make a second class that holds an instance of the first class

faint night
runic egret
#

Ah

#

Wrong kind of class :p

faint night
#

i think i'm getting it... the json response contains two big groups

#

this one

#

and this one

#

that's why there are here to big groups

#

a class containing all that strings

#

and just a single string

severe crest
#

they're 2 objects in this case, which in c# translate to a class/struct

faint night
#

yep

#

and when i have a class in a class

#

i need to serialize that class?

#

Or when i serialize the top one it serializes the rest automatically

severe crest
#

I mean if you wanted to Results class definition itself, could've just been outside of Sundata
the object SunData which has results and status are the only ones needed inside ,
ofc you have to define the fields of results object , which you did but yeah the class itself can be defined in another file even.

runic egret
#

The entire thing gets serialized.

#

Every class involved must be marked as Serializable, but that’s it

faint night
#

and just to confirm

#

that is not possible right?

severe crest
#

no

faint night
#

good

#

now can I say that i more less know how it workss!!! <:

severe crest
# faint night and just to confirm

you can technically do this I meant earlier

[Serializable]
public class Sundata
{
    public Results results;
    public string status;
}
[Serializable]
public class Results
{
    public string sunrise;
    public string sunset;
    public string etc;
    public string etc;
    public string etc;
}```
runic egret
#

You want to think about the “shape” of the data

#

The response from the server isn’t just one big flat object

#

It’s an object that has another object in it

severe crest
#

I love working with BSON for db

runic egret
#

I might switch to that for my soulslike game

#

Lots of 128-bit UUIDs that’d be really darn efficient in binary

#

as compared to their current hex encoding

#

I should really do base64 at the least…

severe crest
#

I got this dataset that was in TSV file it was over 1Gb

#

moved it to BSON it was like 36kb

#

lmao

faint night
severe crest
#

your server response looks for it

runic egret
#

Yes. The object contains another object.

#

So your class needs to have a field that stores another class

severe crest
#

aka objects in json

runic egret
#

SunData contains a Results

#

Therefore, it must have a Results field

faint night
runic egret
#

If you omit this field, then SunData will just contain the status string and nothing else

#

{ "status": "foo" }

severe crest
#

yup. wouldn't be very handy lol

severe crest
# faint night Get it

status was rightfully separated from the Results, by whoever made the original object

faint night
runic egret
#

it's a similar concept, at least

#

except that it doesn't use human-readable text

severe crest
#

so yeah pretty much

runic egret
#

JSON is only allowed to use printable characters

severe crest
#

its just overly optimized for size/speed

runic egret
#

open a jpeg in a text editor to find out what non-printable characters look like

#

It's more efficient.

faint night
runic egret
#

For example, a 32-bit integer can be stored in 4 bytes

#

But if you want to encode that integer in JSON, you must write it out as a number using the 0-9 digits

#

That can take ten characters, so 10 bytes of space

faint night
#

I really appreciate it very much for explaining to me how JSON files works

severe crest
#

they're very handy / powerful

#

thats why they're pretty much everywhere

faint night
#

sure, i started learning them to get the sunset time on a location, and know i like them hehe

#

and And thanks to you, I know i don't need all that to increase performance

#

and i can just leave it like this

#

just an out of curiosity question, how did you created this threat?

severe crest
severe crest
faint night
#

oh, another thing, i forgot to ask you what does exactly do the serializable atributte? i know it must be there, but i dont know what it does...

faint night
#

I don't even know what serialize a var does appart from it makes it vissible on the inspector...

severe crest
#

thats just inside unity, there's more to it else where, on that link it explains more or less.. its a bit of a heabust . Not something you should worry at this moment

faint night
#

thanks for the info

#

i'll take a look

#

...and to your video too

severe crest
# faint night ...and to your video too

oh right those are there too forgot
Ironically those are one of the only few videos I don't do any sort of explainations of code and just plow through showing code no commentary 😅
I need to redo it as its not very useful learning tool

faint night
#

bruhh, i'll be waiting for it hehe

severe crest
# faint night bruhh, i'll be waiting for it hehe

thanks! I'm writing a simple blog while thats in the works though, just find it easier than using my voice.. ughh I kinda envy those youtubers with extrovert enough personality to make vids , but I try push myself not be hermit 🥹

faint night
#

Every single person do it the better way for them...