Solved deserialize string

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Spartan9802

Member
Jan 26, 2017
158
8
18
26
I'm looking for how to deserialize a string get back mysql, deserialize method () asks for a hashmap this is my code:
code_language.skript:
#<-- I recover a serializer item with ItemStack serialize() method, then save it in my database -->
set {_string} to my mysql
set {_item} to {ItemStack}.deserialize({_string})
 
Here's how I serialize my items
Deserialize requires a hashmap and not a string :/
code_language.skript:
#<-- Sauvegarde les armures du joueurs -->  
function saveArmor(p:player, id:number):
    set {_helmet} to helmet of {_p}
    set {_chestplate} to chestplate of {_p}
    set {_leggings} to leggings of {_p}
    set {_boots} to boots of {_p}

    set {_helmet} to "%{_helmet}.serialize()%"
    set {_chestplate} to "%{_chestplate}.serialize()%"
    set {_leggings} to "%{_leggings}.serialize()%"
    set {_boots} to "%{_boots}.serialize()%"
   
    replace "'" with "''" in {_helmet}
    replace "'" with "''" in {_chestplate}
    replace "'" with "''" in {_leggings}
    replace "'" with "''" in {_boots}
   
    update "INSERT INTO `armor` (`id`,`helmet`,`chestplate`,`leggings`,`boots`) VALUES ('%{_id}%','%{_helmet}%','%{_chestplate}%','%{_leggings}%','%{_boots}%');"
[doublepost=1520894993,1520868760][/doublepost]Here is the solution proposed by @Snow-Pyon
It works perfectly
code_language.skript:
function saveItemToMysql(id:number, items:objects):
    set {_json} to "%{_items::*}'s serialized json form%"
    update "INSERT INTO `items` (`id`,`serial`) VALUES ('%{_id}%','%{_json}%');"

function restoreItem(id:number) :: objects:
    set {_json} to the first element out of objects in column "serial" from result of query "SELECT serial FROM `items` WHERE id = '%{_id}%'"
    map json {_json} to {_items::*}
    return {_items::*}
 
Status
Not open for further replies.