Jump to content

How to convert string to table


enzoDs

Recommended Posts

6 minutes ago, enzoDs said:

Hello i need convert string to table and table to string! Thanks

 

With de toJson o other metod :D

Hello enzoDs,

you seem to know about the functions toJSON and fromJSON, don't you? If you have any problems with using these functions then please explain and we will help you :) 

  • Thanks 1
Link to comment
defaultPuestos = {
[1] = "Jefe",
[2] = "Jefe",
[3] = "500",
 
[4] = "Lider",
[5] = "Lider",
[6] = "400",

[7] = "Empleado",
[8] = "Empleado",
[9] = "107",

[10] = "7",
[11] = "Empleado",
[12] = "106",

[13] = "6",
[14] = "Empleado",
[15] = "105",

[16] = "5",
[17] = "Empleado",
[18] = "104",

[19] = "4",
[20] = "Empleado",
[21] = "103",

[22] = "3",
[23] = "Empleado",
[24] = "102",

[25] = "2",
[26] = "Empleado",
[27] = "101",

[28] = "1",
[29] = "Empleado",
[30] = "100",

}

stringTable = toJson(defaultPuestos )

defautPuestos2 = fromJson(stringTable)

 

 

In this case defautPuestos2 would be a table value?

Link to comment
function crearEmpresa ( stringNombre, stringEmpresa )
aclCreateGroup ( tostring((stringEmpresa):gsub(" ", "-")) )
aclGroupAddObject ( aclGetGroup(tostring((stringEmpresa):gsub(" ", "-"))), "user."..getAccountName(getPlayerAccount(getPlayerFromName(stringNombre)) ))
setAccountData ( getPlayerAccount(getPlayerFromName(stringNombre)), "Empresa", tostring((stringEmpresa):gsub(" ", "-")) )
outputChatBox("(( EMPRESAS: "..stringNombre.." creo un empresa llamada "..stringEmpresa.." ))")
addAccount ( tostring((stringEmpresa):gsub(" ", "-")), "*******" )


a = setAccountData ( getAccount(tostring((stringEmpresa):gsub(" ", "-"))), "Puestos", toJSON(defaultPuestos)  )

outputChatBox(tostring(stringTabla))
end
addEvent( "crearEmpresa", true )
addEventHandler( "crearEmpresa", resourceRoot, crearEmpresa ) 

--outputChatBox(tostring(("Hola XD"):gsub(" ", "-")))


function TablaEmpresa (jugador)
empresajugador = getAccountData(getPlayerAccount(getPlayerFromName(jugador)), "Empresa")
tabla = aclGroupListObjects(aclGetGroup(empresajugador))
  
dataPuestos = getAccountData ( getAccount(tostring((empresajugador):gsub(" ", "-"))), "Puestos"  )
  
outputChatBox(dataPuestos)
triggerClientEvent ( getPlayerFromName(jugador), "onPanelAbierto", getPlayerFromName(jugador), tabla,dataPuestos )
end
addEvent( "onPanelAbierto", true )
addEventHandler( "onPanelAbierto", resourceRoot, TablaEmpresa )
function llenarGrid (tablaEmpleados,dataPuesto)
	dataPuestos = fromJSON(dataPuesto)
	DGS:dgsGridListClear( Egrid )
	outputChatBox(unpack(dataPuestos,1))
	for objects,name in pairs(tablaEmpleados)do
		local row = DGS:dgsGridListAddRow ( Egrid )
		DGS:dgsGridListSetItemText ( Egrid, row, 1, tostring((name):gsub("user.", "")))
	end
end
addEvent( "onPanelAbierto", true )
addEventHandler( "onPanelAbierto", localPlayer, llenarGrid )

[21:13:55] WARNING: Empresas\server.Lua:71: Bad argument @ 'toJSON' [Expected bool at argument 2, got string 'none']

 

? i cant unpack the table

Link to comment
8 hours ago, enzoDs said:

WARNING: Empresas/client.Lua:71: Bad argument @ "outputChatBox" [Expected string ar argument 1, got none]

I solve it, thanks!

 

Glad to hear that you got it solved. I was sleeping at that time so I could not respond quickly enough. :) 

  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...