#Could you be able to dm me or to create
1 messages · Page 1 of 1 (latest)
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...
This is an object containing another object
Because one object contains the other
JSON is a way to encode data.
It is made up two major components
objects and arrays
an object always starts with {}
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 ]
and why does satatus doesn't have curly braces?
Because its value is neither an object nor an array.
It is a simple value.
A string value, to be specific.
they probably structured it this way so they could do this:
{
"results" : {
// a bunch of data
},
"status" : "success"
}```
or
```json
{
"results" : null,
"status" : "error"
}```
You're putting a lot of emphasis on the existence of "curly braces" here
but it doesn;t relaly matter why it's just how they chose to structure it
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
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
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 ]
along with true, false, and null
the entire spec is extremely short
true
You should really just go make some small classes and see what they look like when serialized.
I think it will help you to get a mental model.
ohh
Really usefull to know that
The problem is where to find them...
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
oh, sorry i thought you were saying like courses
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
they're 2 objects in this case, which in c# translate to a class/struct
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
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.
The entire thing gets serialized.
Every class involved must be marked as Serializable, but that’s it
no
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;
}```
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
I love working with BSON for db
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…
I got this dataset that was in TSV file it was over 1Gb
moved it to BSON it was like 36kb
lmao
but in that case would be necesary to write this? cs public Results results; on the first class?
yes ofc
your server response looks for it
Yes. The object contains another object.
So your class needs to have a field that stores another class
aka objects in json
Get it
If you omit this field, then SunData will just contain the status string and nothing else
{ "status": "foo" }
yup. wouldn't be very handy lol
status was rightfully separated from the Results, by whoever made the original object
is that kinda JSON file?
just means Binary instead of Javascript
so yeah pretty much
JSON is only allowed to use printable characters
its just overly optimized for size/speed
open a jpeg in a text editor to find out what non-printable characters look like
It's more efficient.
i've seen that there are a way to convert json content into binary... is that the same?
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
I really appreciate it very much for explaining to me how JSON files works
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?
right click on any message Create Thread or the Plus button on discord
not sure about performance wise lol you're still downloading all the data in this case, its just neater without all the needed fields cluttering the model object
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...
hehehe
Thanks
it marks the class as able to serialize , for binary or json or w/e
I don't even know what serialize a var does appart from it makes it vissible on the inspector...
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
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
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 🥹
Every single person do it the better way for them...