3

I'm currently working on a client that has more features than another existing client for a game. One of the functionalities I would like to add is the ability for a user to add an IP address to their favourites and display relevant information of that server (IP, Port, Hostname, Gamemode etc.).

In order to do this I use an API which takes several parameters, such as the IP address and port. It returns some kind of string which contains the information that I need. However I'm having trouble extracting the information I want from the string. I did manage to do it, but I did it quick and dirty by using a dozen substrings to cut out the values of the parameters from the response.

Here's an example of an API call: http://monitor.sacnr.com/api/?IP=149.202.89.123&Port=7777&Action=info

Initially I thought the response was some kind of JSON string, but after some googling I found a question on Stackoverflow about stdClass. Apparently it's some kind of generic PHP class.

So my question is: how can I convert the response of the API to say JSON or XML, so I can easily parse it?

Example response:

O:8:"stdClass":18:{s:8:"ServerID";s:7:"1780392";s:2:"IP";s:14:"149.202.89.123";s:4:"Port";s:4:"7777";s:8:"Hostname";s:32:"Next Generation Roleplay (0.3.7)";s:8:"Gamemode";s:14:"NG:RP v3.0.409";s:8:"Language";s:7:"English";s:3:"Map";s:13:"NG-Gaming.net";s:10:"MaxPlayers";s:3:"500";s:7:"Players";s:3:"131";s:7:"Version";s:8:"0.3.7-R2";s:8:"Password";s:1:"0";s:4:"Time";s:5:"20:00";s:6:"WebURL";s:13:"ng-gaming.net";s:4:"Rank";s:3:"112";s:10:"AvgPlayers";s:5:"88.27";s:9:"HostedTab";s:1:"1";s:10:"LastUpdate";s:10:"1486138780";s:12:"TotalServers";s:4:"1305";}
Barathon
  • 47
  • 3
  • 8
  • It is not a JSON string. –  Feb 03 '17 at 16:31
  • 4
    It's probably better if you write a small PHP script like [this one](https://eval.in/729960) and have C# get the JSON string instead. Probably easier than writing a C# php object unserializer. – apokryfos Feb 03 '17 at 16:32
  • Or https://sourceforge.net/projects/csphpserial/ may work – apokryfos Feb 03 '17 at 16:34
  • 2
    This format changes in between PHP versions ... The only sane thing is for the API developers to move away from it. – Narf Feb 03 '17 at 16:37

1 Answers1

1

Try using the Sharp Serialization Library.

As per their description: "Sharp Serialization Library serializes and deserializes primitives, ArrayLists and Hashtables, compatible with PHP serialize()"

SteveD
  • 729
  • 6
  • 13