# KVData
The hosted KV data.
# Properties
# string key
The data key.
# string value
The data value.
# Displaying Rankings in the Mini Game Center
If developers want to display game rankings in the Mini Game center, they need to store the ranking data to the appropriate key/value. A ranking corresponds to a key, and there are multiple keys for multiple rankings. Developers can also set the key and related ranking properties in the Mini Program admin console on the WeChat Official Accounts Platform (mp.weixin.qq.com) by selecting Settings > Game > Ranking Settings. The value must be a string serialized into JSON Object format. The top-level JSON Object must contain the wxgame
field, which is composed as follows:
Property | Type | Required | Description |
---|---|---|---|
score | Int32 | Yes | The score of the ranking |
update_time | Int64 | Yes | The time when the score was last updated, which is expressed as a Unix timestamp. |
Note: Developers cannot define other fields under the wxgame
field, but can define those with the same level as the wxgame
field. For example, a detail
field can be defined to store the status before the score is achieved.
# Example
A Mini Game is configured with a score ranking to record the scores and the time spent getting the score (which is displayed on the in-game rankings). A cost_ms
field can be defined at the same level as wxgame
to store the time (in ms).
Assign a key, such as "score", that is not in conflict with the defined hosted data key as the ranking key.
If a player creates a new record of 16 scores after playing 36500 ms, the score ranking needs to be updated. If the current timestamp is 1513080573, the content of the complete value before serialization is as follows:
{
"wxgame": {
"score":16,
"update_time": 1513080573
},
"cost_ms":36500
}
The final value that has been serialized to a string is "{"wxgame":{"score":16,"update_time": 1513080573},"cost_ms":36500}".