View Single Post
muukis
Veteran Member
Join Date: Apr 2009
Old 07-13-2018 , 04:42   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #49

I managed to get the self signed certificate to work - Thanks for helping me out at GitHub.

However, I have another problem... this does not work:
Code:
#include <sourcemod>
#include <ripext>

public void OnPluginStart()
{
	PrintToServer("Testing JSONObject...");
	JSONObject obj = new JSONObject();
	obj.SetString("test", "ð");
	decl String:test[10];
	obj.GetString("test", test, sizeof(test));
	delete obj;
	PrintToServer("test: %s", test);
	PrintToServer("Finished testing JSONObject");
}
What the server responds is this:
Code:
sm plugins load test
Testing JSONObject...
L 07/13/2018 - 11:35:58: [SM] Native "JSONObject.GetString" reported: Could not retrieve value for key 'test'
L 07/13/2018 - 11:35:58: [SM] Displaying call stack trace for plugin "test.smx":
L 07/13/2018 - 11:35:58: [SM]   [0]  Line 10, test.sp::OnPluginStart()
[SM] Loaded plugin test.smx successfully.
I am trying to send player name to a REST API. It seems some player names fail to work with the JSONObject. Not always though, and that is what I don't quite understand. I am thinking base64 encoding the names, but I was hoping there was a better solution for this.

Here's another example:
Code:
#include <sourcemod>
#include <ripext>

public void OnPluginStart()
{
	PrintToServer("Testing JSONObject...");
	JSONObject obj = new JSONObject();
	obj.SetString("test1", "We start here...");
	obj.SetString("test2", "ð");
	obj.SetString("test3", ".. and here we are");
	decl String:json[64];
	obj.ToString(json, sizeof(json));
	delete obj;
	PrintToServer("json: %s", json);
	PrintToServer("Finished testing JSONObject");
}
What the server responds is this:
Code:
sm plugins load test
Testing JSONObject...
json: {"test1": "We start here...", "test3": ".. and here we are"}
Finished testing JSONObject
[SM] Loaded plugin test.smx successfully.
__________________
Monster Hunter

Though certainly not superhuman, the man's prowess inspires an excess of whispered rumors. But those rumors remain in the realm of speculation.

Last edited by muukis; 07-13-2018 at 05:25.
muukis is offline