Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Object
- var action: String
- var payloads: Array
- func _init(_action: String, _payloads: Array) -> void:
- action = _action
- payloads = _payloads
- func tostring() -> String:
- var serialize_dict: Dictionary = {"a": action}
- for i in range(len(payloads)):
- serialize_dict["p%d" % i] = payloads[i]
- var data: String = JSON.stringify(serialize_dict)
- return data
- static func json_to_action_payloads(json_str: String) -> Array:
- var jaction: String
- var jpayloads: Array = []
- var obj_dict: Dictionary = JSON.parse_string(json_str)
- for key in obj_dict.keys():
- var value = obj_dict[key]
- if key == "a":
- jaction = value
- elif key[0] == "p":
- var index: int = key.split_floats("p", true)[1]
- jpayloads.insert(index, value)
- return [jaction, jpayloads]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement