本文整理汇总了C++中JSONValue::GetObject方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONValue::GetObject方法的具体用法?C++ JSONValue::GetObject怎么用?C++ JSONValue::GetObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONValue
的用法示例。
在下文中一共展示了JSONValue::GetObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadJSON
bool Animatable::LoadJSON(const JSONValue& source, bool setInstanceDefault)
{
if (!Serializable::LoadJSON(source, setInstanceDefault))
return false;
SetObjectAnimation(0);
attributeAnimationInfos_.Clear();
JSONValue value = source.Get("objectanimation");
if (!value.IsNull())
{
SharedPtr<ObjectAnimation> objectAnimation(new ObjectAnimation(context_));
if (!objectAnimation->LoadJSON(value))
return false;
SetObjectAnimation(objectAnimation);
}
JSONValue attributeAnimationValue = source.Get("attributeanimation");
if (attributeAnimationValue.IsNull())
return true;
if (!attributeAnimationValue.IsObject())
{
URHO3D_LOGWARNING("'attributeanimation' value is present in JSON data, but is not a JSON object; skipping it");
return true;
}
const JSONObject& attributeAnimationObject = attributeAnimationValue.GetObject();
for (JSONObject::ConstIterator it = attributeAnimationObject.Begin(); it != attributeAnimationObject.End(); it++)
{
String name = it->first_;
JSONValue value = it->second_;
SharedPtr<ValueAnimation> attributeAnimation(new ValueAnimation(context_));
if (!attributeAnimation->LoadJSON(it->second_))
return false;
String wrapModeString = source.Get("wrapmode").GetString();
WrapMode wrapMode = WM_LOOP;
for (int i = 0; i <= WM_CLAMP; ++i)
{
if (wrapModeString == wrapModeNames[i])
{
wrapMode = (WrapMode)i;
break;
}
}
float speed = value.Get("speed").GetFloat();
SetAttributeAnimation(name, attributeAnimation, wrapMode, speed);
it++;
}
return true;
}
示例2: LoadJSON
void Localization::LoadJSON(const JSONValue& source)
{
for (JSONObject::const_iterator i = source.GetObject().begin(); i != source.GetObject().end(); ++i)
{
QString id = MAP_KEY(i);
if (id.isEmpty())
{
URHO3D_LOGWARNING("Localization::LoadJSON(source): string ID is empty");
continue;
}
const JSONObject& langs = MAP_VALUE(i).GetObject();
for (JSONObject::const_iterator j = langs.begin(); j != langs.end(); ++j)
{
const QString& lang = MAP_KEY(j);
if (lang.isEmpty())
{
URHO3D_LOGWARNING("Localization::LoadJSON(source): language name is empty, string ID=\"" + id + "\"");
continue;
}
const QString stringRef = MAP_VALUE(j).GetString();
if (stringRef.isEmpty())
{
URHO3D_LOGWARNING(
"Localization::LoadJSON(source): translation is empty, string ID=\"" + id + "\", language=\"" + lang + "\"");
continue;
}
if (strings_[StringHash(lang)][StringHash(id)] != s_dummy)
{
URHO3D_LOGWARNING(
"Localization::LoadJSON(source): override translation, string ID=\"" + id + "\", language=\"" + lang + "\"");
}
strings_[StringHash(lang)][StringHash(id)] = stringRef;
if (!languages_.contains(lang))
languages_.push_back(lang);
if (languageIndex_ == -1)
languageIndex_ = 0;
}
}
}
示例3: LoadJSON
bool ObjectAnimation::LoadJSON(const JSONValue& source)
{
attributeAnimationInfos_.Clear();
JSONValue attributeAnimationsValue = source.Get("attributeanimations");
if (attributeAnimationsValue.IsNull())
return true;
if (!attributeAnimationsValue.IsObject())
return true;
const JSONObject& attributeAnimationsObject = attributeAnimationsValue.GetObject();
for (JSONObject::ConstIterator it = attributeAnimationsObject.Begin(); it != attributeAnimationsObject.End(); it++)
{
String name = it->first_;
JSONValue value = it->second_;
SharedPtr<ValueAnimation> animation(new ValueAnimation(context_));
if (!animation->LoadJSON(value))
return false;
String wrapModeString = value.Get("wrapmode").GetString();
WrapMode wrapMode = WM_LOOP;
for (int i = 0; i <= WM_CLAMP; ++i)
{
if (wrapModeString == wrapModeNames[i])
{
wrapMode = (WrapMode)i;
break;
}
}
float speed = value.Get("speed").GetFloat();
AddAttributeAnimation(name, animation, wrapMode, speed);
}
return true;
}
示例4: Update
//.........这里部分代码省略.........
for (uint i=0; i < processEvents.Size(); ++i)
{
SocketEvent *event = processEvents[i];
if (!event)
continue;
// User connected
if (event->type == SocketEvent::Connected)
{
if (!UserConnection(event->connection))
{
WebSocket::UserConnectionPtr userConnection(new WebSocket::UserConnection(context_, event->connection));
connections_.Push(userConnection);
// The connection does not yet have an ID assigned. Tundra server will assign on login
LogDebug(LC + String("New WebSocket connection."));
}
}
// User disconnected
else if (event->type == SocketEvent::Disconnected)
{
for(UserConnectionList::Iterator iter = connections_.Begin(); iter != connections_.End(); ++iter)
{
if ((*iter) && (*iter)->WebSocketConnection() == event->connection)
{
tundraServer->RemoveExternalUser(Urho3D::StaticCast<::UserConnection>(*iter));
if (!(*iter)->userID)
LogDebug(LC + "Removing non-logged in WebSocket connection.");
else
LogInfo(LC + "Removing WebSocket connection with ID " + String((*iter)->userID));
connections_.Erase(iter);
break;
}
}
}
// Data message
else if (event->type == SocketEvent::Data && event->data.get())
{
WebSocket::UserConnectionPtr userConnection = UserConnection(event->connection);
if (userConnection)
{
kNet::DataDeserializer dd(event->data->GetData(), event->data->BytesFilled());
u16 messageId = dd.Read<u16>();
// LoginMessage
if (messageId == cLoginMessage)
{
bool ok = false;
String loginDataString = ReadUtf8String(dd);
// Read optional protocol version
if (dd.BytesLeft())
userConnection->protocolVersion = (NetworkProtocolVersion)dd.ReadVLE<kNet::VLE8_16_32>();
JSONValue json;
ok = json.FromString(loginDataString);
if (ok)
{
JSONObject jsonObj = json.GetObject();
for (JSONObject::ConstIterator i = jsonObj.Begin(); i != jsonObj.End(); ++i)
userConnection->properties[i->first_] = i->second_.ToVariant();
userConnection->properties["authenticated"] = true;
bool success = tundraServer->AddExternalUser(Urho3D::StaticCast<::UserConnection>(userConnection));
if (!success)
{
LogInfo(LC + "Connection ID " + String(userConnection->userID) + " login refused");
toDisconnect.Push(userConnection);
}
else
LogInfo(LC + "Connection ID " + String(userConnection->userID) + " login successful");
}
}
else
{
// Only signal messages from authenticated users
if (userConnection->properties["authenticated"].GetBool() == true)
{
// Signal network message. As per kNet tradition the message ID is given separately in addition with the rest of the data
NetworkMessageReceived.Emit(userConnection.Get(), messageId, event->data->GetData() + sizeof(u16), event->data->BytesFilled() - sizeof(u16));
// Signal network message on the Tundra server so that it can be globally picked up
tundraServer->EmitNetworkMessageReceived(userConnection.Get(), 0, messageId, event->data->GetData() + sizeof(u16), event->data->BytesFilled() - sizeof(u16));
}
}
}
else
LogError(LC + "Received message from unauthorized connection, ignoring.");
event->data.reset();
}
else
event->data.reset();
SAFE_DELETE(event);
}
for (uint i = 0; i < toDisconnect.Size(); ++i)
{
if (toDisconnect[i])
toDisconnect[i]->Disconnect();
}
}
示例5: ToRapidjsonValue
static void ToRapidjsonValue(rapidjson::Value& rapidjsonValue, const JSONValue& jsonValue, rapidjson::MemoryPoolAllocator<>& allocator)
{
switch (jsonValue.GetValueType())
{
case JSON_NULL:
rapidjsonValue.SetNull();
break;
case JSON_BOOL:
rapidjsonValue.SetBool(jsonValue.GetBool());
break;
case JSON_NUMBER:
{
switch (jsonValue.GetNumberType())
{
case JSONNT_INT:
rapidjsonValue.SetInt(jsonValue.GetInt());
break;
case JSONNT_UINT:
rapidjsonValue.SetUint(jsonValue.GetUInt());
break;
default:
rapidjsonValue.SetDouble(jsonValue.GetDouble());
break;
}
}
break;
case JSON_STRING:
rapidjsonValue.SetString(jsonValue.GetCString(), allocator);
break;
case JSON_ARRAY:
{
const JSONArray& jsonArray = jsonValue.GetArray();
rapidjsonValue.SetArray();
rapidjsonValue.Reserve(jsonArray.Size(), allocator);
for (unsigned i = 0; i < jsonArray.Size(); ++i)
{
rapidjson::Value value;
rapidjsonValue.PushBack(value, allocator);
ToRapidjsonValue(rapidjsonValue[i], jsonArray[i], allocator);
}
}
break;
case JSON_OBJECT:
{
const JSONObject& jsonObject = jsonValue.GetObject();
rapidjsonValue.SetObject();
for (JSONObject::ConstIterator i = jsonObject.Begin(); i != jsonObject.End(); ++i)
{
const char* name = i->first_.CString();
rapidjson::Value value;
rapidjsonValue.AddMember(name, value, allocator);
ToRapidjsonValue(rapidjsonValue[name], i->second_, allocator);
}
}
break;
default:
break;
}
}