本文整理汇总了C++中JSONValue::type方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONValue::type方法的具体用法?C++ JSONValue::type怎么用?C++ JSONValue::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONValue
的用法示例。
在下文中一共展示了JSONValue::type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: url
/*!
\brief Fetches game achievement completion values.
This method fetches the game completion values for the game app ID \p appID.
\param appID The app ID we want the achievement completion values for.
\return A \c QHash map with achievements and completion values.
*/
QHash< QString, float >
Steam::fetchAchievementCompletion( int appID )
{
if( appID <= 0 )
return( QHash< QString, float >() );
QUrl url( QL( "http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v2/" ) );
url.addQueryItem( QL( "gameid" ), QString::number( appID ) );
QNetworkRequest request( url );
QNetworkReply *reply = d->network->get( request );
while( ! reply->isFinished() )
qApp->processEvents();
QByteArray data = reply->readAll();
reply->deleteLater();
reply = NULL;
if( data.isEmpty() )
return( QHash< QString, float >() );
JSONStreamReader json;
JSONObject *root = json.read( data );
if( ! root || json.hasError() )
{
delete root;
root = NULL;
SteamPrivate::jsonError( json );
return( QHash< QString, float >() );
}
JSONList *achievements = NULL;
JSONObject *achievementpercentages = root->valueObject( QL( "achievementpercentages" ) );
if( achievementpercentages )
achievements = achievementpercentages->valueList( QL( "achievements" ) );
QHash< QString, float > completion;
for( int i = 0; achievements && i < achievements->count(); i++ )
{
JSONValue *val = achievements->at( i );
JSONObject *achievement = NULL;
if( val->type() == JSONValue::T_Object )
achievement = dynamic_cast< JSONObject * >( val );
if( achievement )
{
QString name = achievement->valueScalar( QL( "name" ) )->sValue();
float percent = achievement->valueScalar( QL( "percent" ) )->dValue();
completion.insert( name, percent );
}
}
delete root;
root = NULL;
return completion;
}
示例2: QL
/*!
\brief Processes a app ID list reply.
The data is rather big and in JSON format. We parse it, read it and return it
to the main window as a signal.
\param data The data to be parsed.
*/
void
Steam::processReplyAppIDs( const QByteArray &data )
{
WAITCURSOR;
QHash< QString, int > map;
if( data.isEmpty() )
return;
JSONStreamReader jsonReader;
JSONObject *json = jsonReader.read( data );
if( ! json || jsonReader.hasError() )
{
SteamPrivate::jsonError( jsonReader );
return;
}
JSONList *app = NULL;
JSONObject *apps = NULL;
JSONObject *applist = json->valueObject( QL( "applist" ) );
if( applist )
apps = applist->valueObject( QL( "apps" ) );
if( apps )
app = apps->valueList( QL( "app" ) );
for( int i = 0; app && i < app->count(); i++ )
{
JSONValue *aApp = NULL;
aApp = app->at( i );
if( aApp->type() == JSONValue::T_Object )
{
JSONObject *obj = dynamic_cast< JSONObject * >( aApp );
map.insert( obj->valueScalar( QL( "name" ) )->sValue(),
obj->valueScalar( QL( "appid" ) )->iValue() );
}
}
delete json;
json = NULL;
emit( appIDs( map ) );
}