-
-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fromJSON parses JSON in wrong way #1946
Comments
It's because MTA is retarded. outputDebugString(fromJSON('[{"name": "Piorun", "position": { "x": 0, "y": 0, "z": 0 }}]')) |
It's really misleading. Since collections are inside [
{
"_id":"5fe513b7132fc155b571d479",
"modelId":567,
"position":{
"x":0,
"y":0,
"z":0
},
"rotation":{
"x":0,
"y":0,
"z":0
},
"__v":0
}
] and it's not working properly (tbh it's not working at all) |
Ok don't know why but it's working when I added |
Not sure if changing it would break backwards compatibility. The issue has been discussed before, although not sure in which issue (that is which #). Perhaps we should automatically add the |
Ah, I see. Its done like this so that this works: local name, weapon, ammo = fromJSON("[\"Desert Eagle\", 24, 147]") |
Don't change it, please. It is working perfectly fine and all of my resources use this method and I really don't feel like rewriting every one of my resources just because one user isn't satisfied with it. |
I think it should be added to 1.6 so it doesn't have to be backward compatible with 1.5.x |
This function was working the same way as today since 2008. Do you really think backwards compatibility isn't important? Everyone will have to rewrite every one of their resources since 2008 that is using JSON, just because you don't like the way it is working. Don't be selfish. |
I'm not selfish? I just know that if I have 1.x version of anything it doesn't have to be backward compatible with 1.y (where
For me - it's bug because It's not parsing JSON properly. JSON format with added square bracket's isn't proper JSON format Lastly: good programmer would create some simple one function to add those brackets (like I do) so everything that should be change would be only one function. |
MTA is very backwards compatible, like we still have MTA 1.0 functions "deprecated". Also, every value in the array will result in a separate variable, eg.: local v1, v2 = fromJSON('["value1", "value2"]')
print(v1, v2) -- value1, value2 What we could do: Add an argument which indicates there's only one value (thus no extra array needed). |
Also backwards compatible doesn't mean that something written in 1.6 should work in 1.5.8. It means that something written in 1.5.8 should work in 1.6, and in the case that you are saying, that wouldn't work. This function works, and the first thing you should've done was try toJSON with a table and see the outcome, then adapt to it. Not open a bug report. |
@pawel-miczka, your example is incorrect. It works as intended: |
There's weird thing that happens to |
Use iprint. |
It isn't parsing it in the wrong way, this is how fromJSON works. |
Describe the bug
Today I noticed that fromJSON function doesn't work for JSON collections. It returns only first found object inside object or collection.
To reproduce
Two things:
Run inside MTA this:
and open web console (ie. Google Chrome DevTools) and use this code:
Expected behaviour
Should return this:
Screenshots
none
Version
everything newest
Additional context
none
The text was updated successfully, but these errors were encountered: