C
C#9mo ago
- SinAw

✅ problem

I call a function that returns something like this
c#
"["value 2","value 1"]"
c#
"["value 2","value 1"]"
How can I turn this into a Array ?
18 Replies
cap5lut
cap5lut9mo ago
so how do u print this string? so give us some basic information (the code u showed earlier as well)
- SinAw
- SinAw9mo ago
this is a http request to lua function C#
c#
mta = new MTA("5.42.223.36", 22005, "user", "pass");
MTA_LuaArgs args = new MTA_LuaArgs();
var item = mta.CallFunction("discord_bot", "getInfo", args);
await command.RespondAsync(item);
c#
mta = new MTA("5.42.223.36", 22005, "user", "pass");
MTA_LuaArgs args = new MTA_LuaArgs();
var item = mta.CallFunction("discord_bot", "getInfo", args);
await command.RespondAsync(item);
Lua
local originalGetPlayerCount = getPlayerCount
function getInfo()
return getServerName() , "Player Count : "..tonumber(originalGetPlayerCount())
end
local originalGetPlayerCount = getPlayerCount
function getInfo()
return getServerName() , "Player Count : "..tonumber(originalGetPlayerCount())
end
Angius
Angius9mo ago
I would start by questioning why a method returns this string in the first place and not an array
cap5lut
cap5lut9mo ago
because, i might not be able to help ya, so if anyone else sees this thread they might be able to help if they see the whole thing
Angius
Angius9mo ago
What do you mean "http request to a LUA function"? I see no HTTP requests here
cap5lut
cap5lut9mo ago
we were in #chat first
Angius
Angius9mo ago
Ah, I lack context then, carry on
cap5lut
cap5lut9mo ago
now all context is given this string, how u do u print it? thats not given from the shown code or do u see it via debugger?
- SinAw
- SinAw9mo ago
I actually see ["Value 1","Value 2"] I just wanted to say that this is the type of string
cap5lut
cap5lut9mo ago
if its ["Value 1","Value 2"] (which is valid json, a list with 2 string elements), instead of "["Value 1","Value 2"]" which is invalid json, it makes quite a difference u r using Newtonsoft.Json, right?
- SinAw
- SinAw9mo ago
yes
cap5lut
cap5lut9mo ago
and u want to deserialize it to a string array? as in string[]? because that would be a simple string[] arr = JsonConvert.DeserializeObject<string[]>(content); what type is item btw?
- SinAw
- SinAw9mo ago
ow it worked, thank you very much
cap5lut
cap5lut9mo ago
if it worked, then this ⤴️ with the extra " at the start and the end was just about how u displayed the content and if u r on .NEt 7 or later u should really look into using System.Text.Json instead, its since .net 7 the defacto standard unless u have some niche cases regarding invalid json @- SinAw if ur question is answered, please mark this thread as that by $close -ing it
MODiX
MODiX9mo ago
Use the /close command to mark a forum thread as answered
- SinAw
- SinAw9mo ago
ok i use it , thank you very much $close -ing
MODiX
MODiX9mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server