Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

c# - What do I look for in an API response to get the fields?

I want to display the number of players online, using this api query. I got stuck receiving the number of players in the message.

I use the following code in script:

SampQuery api = new SampQuery("184.103.47.77", 7777, 'i');

string sStatus = String.Format("Online players: {0}", /* STUCK HERE */);
onlinePlayers.Text = sStatus;

How can I get data from the api variable into the status string?

This is the API I'm using:

https://github.com/zeelorenc/SA-MP-Server-Query-Class


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looking at the linked example, you need to do four things:

  1. Call api.Read(), as shown in the sample. So far, you have only set up an API call. You don't actually talk to the API until you call the read() method. Don't forget to assign the result to a variable.
  2. Run ALL the code in the sample. This will print out a list of key/value pairs. That will tell you what fields are available in the API.
  3. Look at the output from step #2, to figure out what key you need.
  4. Use the key identified in step 3 to create the expression for your /* Stuck here */ comment

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...