Raised This Month: $90 Target: $400
 22% 

REST in Pawn - Communicate with JSON REST APIs


Post New Thread Reply   
 
Thread Tools Display Modes
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 08-28-2018 , 05:00   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #51

New release:
  • Possible fix for the crashes (thanks Peace-Maker)
  • Added ConnectTimeout, FollowLocation and Timeout properties to HTTPClient (thanks CrazyHackGUT)
  • Added error message to HTTPRequestCallback
Download

Please let me know if you're still experiencing crashes, as I haven't been able to reproduce them myself.
__________________
DJ Tsunami is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 08-28-2018 , 15:10   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #52

Well, i'm pleased to that you are back to working out on extension. This is really nice extension.
I'm also glad that part of the functionality was taken from my fork.

Good job!
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
Mitchell
~lick~
Join Date: Mar 2010
Old 10-25-2018 , 18:45   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #53

i'm not sure why but now every site I try returns 404 status after the tf2 update today. Was working fine before the update.
Guess express was returning 404 for missing a slight slash '/'
__________________

Last edited by Mitchell; 10-25-2018 at 19:47.
Mitchell is offline
slekenda
Junior Member
Join Date: Aug 2017
Old 11-21-2018 , 03:31   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #54

Hello!

I'm trying to load JSON from a file, but I'm getting an error. Anyone any help?

PHP Code:

    char path
[PLATFORM_MAX_PATH 1];
    
BuildPath(Path_SMpathsizeof(path), "data/match.json");
    
PrintToServer("FileExists %d"FileExists(path));

    
JSONObject data JSONObject.FromFile(path); 
Error:
PHP Code:
"[RIPEXT] Invalid JSON in line -1, column -1: unable to 
open addons/sourcemod/data/match.json: No such file or directory" 
PrintToServer("FileExists %d", FileExists(path)); <- This prints "FileExists: 1"

File:
PHP Code:
{
    
"map""de_dust2",
    
"uuid""awawras4aw4as4sa"

EDIT: Apparently when I add the absolute path of the JSON file to "JSONObject data = JSONObject.FromFile(path);" it works but not with the Path_SM

Last edited by slekenda; 11-21-2018 at 05:42.
slekenda is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 11-22-2018 , 12:00   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #55

Thanks slekenda, this should be fixed in 1.0.6.
__________________
DJ Tsunami is offline
Nerus
Senior Member
Join Date: Aug 2010
Location: Poland
Old 12-09-2018 , 18:41   Re: REST in Pawn - Communicate with JSON REST APIs
Reply With Quote #56

How to get nested array from json?

I need to get value of total_time_played

Result
PHP Code:
public void OnTodoReceived(HTTPResponse responseany value)
{
    if (
response.Status != HTTPStatus_OK)
    {
        
ThrowError("Failed to retrieve data from web!");
        return;
    }

    if (
response.Data == null
    {
        
ThrowError("Invalid JSON response!");
        return;
    }

    
// Indicate that the response is a JSON array
    
JSONObject json view_as<JSONObject>(response.Data);
    
JSONObject playerstats view_as<JSONObject>(json.Get("playerstats"));

    
delete json;

    
JSONArray stats view_as<JSONArray>(playerstats.Get("stats"));

    
delete playerstats;

    
JSONObject total_time_played view_as<JSONObject>(stats.Get(2));

    
delete stats;

    
char name[32];
    
total_time_played.GetString("name"name32);

    
int time = -1;

    if(!
StrEqual(name"total_time_played"false))
    {
        
delete total_time_played;

        
ThrowError("Invalid element '%s'"name);

        return;
    }

    
time total_time_played.GetInt("value");
    
    
delete total_time_played;

    if(
time 0)
    {
        
ThrowError("Time was not parsed from JSON file correctly!");

        return;
    }

    
PrintToServer("total_time_played = %d"time);

BTW, @DJ Tsunami can you add something like default value on get.
Attached Files
File Type: txt example.txt (13.6 KB, 22 views)

Last edited by Nerus; 12-10-2018 at 17:43. Reason: [SOLVED]
Nerus is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:51.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode