-
Notifications
You must be signed in to change notification settings - Fork 2
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
[haxe.org/manual] Parsing JSON #22
Comments
How do you iterate through the keys of a parsed JSON object? |
@daverave1212 The return type of var myObj:haxe.DynamicAccess<Dynamic> = haxe.Json.parse('{"foo": true, "bar": 2}');
for (key in myObj.keys()) trace(key, myObj.get(key));
// or using Haxe 4 syntax:
for (key => value in myObj) trace(key, value); If you are sure that all the values in a given object will have the same type, you can use var myObj:haxe.DynamicAccess<Int> = haxe.Json.parse('{"foo": 1, "bar": 2}');
for (key => value in myObj) {
// here, `value` is `Int`, rather than `Dynamic` as in the previous example
trace(key, value);
} |
Is there a way to parse maps from JSON into actual maps? I can iterate through an array or even push into an array. An example: https://try.haxe.org/#08f25 |
@KaiSD I'd recommend using a library like json2object or tink_json for that. |
Parsing JSON - Haxe - The Cross-platform Toolkit
Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.
https://haxe.org/manual/std-Json-parsing.html
The text was updated successfully, but these errors were encountered: