void JsionParse::scanForInfo()
{
QJsonArray subJsonarray;
QString subFlags;
/*
*doWhat= "realmForServerList" 扫服务器
* "unionForPlayerList" 扫工会的 成员列表
* "playerForInfo" 玩家基础信息 包含成就
* "playerForPetSLots" 宠物巣
* "playerForMounts" 坐骑
*/
//qDebug() << "JsionParse(QString):" ;
QJsonParseError jsonErr;
QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(jsonStr.toUtf8(),&jsonErr);
if (jsonErr.error == QJsonParseError::NoError)
{
if (myjsonDoc1.isEmpty()){
qDebug()<<"the json is empty!";
}
if (myjsonDoc1.isObject()){
//qDebug()<<"json is object";
QJsonObject jobj = myjsonDoc1.object();
QStringList jsonkeylist = jobj.keys();
qDebug()<<"jsonkeylist="<<jsonkeylist.count();
QJsonObject::iterator it = jobj.begin();
while(it != jobj.end())
{
//qDebug() << "------------------";
switch (it.value().type())
{
case QJsonValue::String:
{
qDebug()<<"type is String!";
if(doWhat=="playerForInfo" && it.key()=="name"){
playerName = it.value().toDouble();
//qDebug()<< "playerName = " << playerName;
}
qDebug()<<it.key()<<"="<< it.value().toString();
break;
}
case QJsonValue::Array:
{
qDebug()<<"type is array!";
subFlags = it.key();
/*
*flags判断: petSlots = 战斗宠物列表
* members = 工会成员列表
* "news" = 工会新闻列表
*/
//底层数量,如 宠物槽3 人员400 坐骑?
subJsonarray = it.value().toArray();
qDebug() << "flags="<<subFlags << "count="<<subJsonarray.count()<<endl ;
//qDebug()<<subJsonarray;
//qDebug()<<"index 1 ="<<subarray.at(0).toDouble();
//qDebug()<<"index 2 ="<<subarray.at(1).toString();
//qDebug()<<"index 3 ="<<subarray.at(2).toBool();
break;
}
case QJsonValue::Bool:
//qDebug()<<"type is bool!";
//qDebug()<<it.key()<<"="<<it.value().toBool();
break;
case QJsonValue::Double:
{
qDebug()<<"type is Double!";
//成就点 工会or个人需判断
if(it.key()=="achievementPoints"){
achievementPoints = it.value().toDouble();
}
//服务器组
if(it.key() =="battlegroup"){
}
//阵营
if(it.key() =="side"){
//side = 1 部落 0 联盟
}
//等级
if(it.key() =="level"){
//工会等级 人物等级
}
//种族 2 血精灵
if(it.key() =="class"){
}
//性别 1=女
if(it.key() =="gender"){
}
qDebug()<<it.key()<<"="<<it.value().toDouble();
break;
}
case QJsonValue::Object:
{
qDebug()<<"type is Object!";
/*
* "mounts": =坐骑表 Object
* pets =战斗宠物列表 Object
*/
if(it.key() == "pets"){
pet_num = it.value().toObject().value("numCollected").toDouble();
}
if(it.key() == "mounts"){
mount_num = it.value().toObject().value("numCollected").toDouble();
}
qDebug()<<it.key()<<"="<<it.value().toObject();
break;
}
case QJsonValue::Null:
qDebug()<<"type is null!";
qDebug()<<it.key()<<"=null";
break;
case QJsonValue::Undefined:
qDebug()<<"type is Undefined!";
break;
}
it++;
}
}
}
if(doWhat == "realmForServerList"){
for(int i=0;i<subJsonarray.count();i++)
{
if(subFlags == "realms"){
qDebug() << subJsonarray.at(i).toObject().value("battlegroup").toString();
QString type = subJsonarray.at(i).toObject().value("type").toString();
realmName = subJsonarray.at(i).toObject().value("name").toString();
QString group = subJsonarray.at(i).toObject().value("battlegroup").toString();
QString stringR = realmName + "+" + type + "+" + group; //构造特定格式 emit
emit realmForServerList_Return(stringR);
}
}
}
if(doWhat == "unionForPlayerList"){
QJsonObject::iterator it_sub;
for(int i=0;i<subJsonarray.count();i++)
{
if(subFlags == "members"){
it_sub = subJsonarray.at(i).toObject().value("character").toObject().find("name");
playerName = it_sub.value().toString();
QString stringR = countryName+"_"+realmName + "+" + unionName+ "+" + playerName; //构造特定格式 emit
emit unionForPlayerList_Return(stringR);
}
}
}
if(doWhat == "playerForPetSLots"){
QJsonObject::iterator it_sub;
QJsonArray petslots_subJsonarray;
for(int i=0;i<subJsonarray.count();i++)
{
if(subFlags == "petSlots"){
it_sub = subJsonarray.at(i).toObject().find("battlePetGuid");
petSlots += (it_sub.value().toString()+"/");
petslots_subJsonarray = subJsonarray.at(i).toObject().value("abilities").toArray();
for(int j=0;j<petslots_subJsonarray.count();j++){
//qDebug()<< "--" << petslots_subJsonarray.at(j).toDouble();
petSlots += QString::number(petslots_subJsonarray.at(j).toDouble())+"/";
}
emit playerForPetSLots_Return(petSlots);
}
}
}
if(doWhat == "playerForInfo")
{
emit playerForInfo_Return(achievementPoints);
}
if(doWhat == "playerForPet")
{
emit playerForPet_Return(pet_num);
}
if(doWhat == "playerForMounts")
{
emit playerForMounts_Return(mount_num);
}
}