本文整理汇总了C++中JSONValue::IsObject方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONValue::IsObject方法的具体用法?C++ JSONValue::IsObject怎么用?C++ JSONValue::IsObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONValue
的用法示例。
在下文中一共展示了JSONValue::IsObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseJsonStr
void CTestJSON::parseJsonStr( const std::wstring& strJsonStr )
{
JSONValue* jsInput = JSON::Parse(strJsonStr.c_str());
if (jsInput == NULL || !jsInput->IsObject())
{
return;
}
JSONObject::const_iterator itResult = jsInput->AsObject().find(L"result");
if (itResult != jsInput->AsObject().end())
{
std::wstring strResult = itResult->second->AsString();
std::wcout << L"result" << L":" << strResult << std::endl;
}
JSONObject::const_iterator itLove = jsInput->AsObject().find(L"Love");
if (itLove != jsInput->AsObject().end())
{
std::wstring strResult = itLove->second->AsString();
std::wcout << L"Love" << L":" << strResult << std::endl;
}
JSONArray jsArray;
JSONObject::const_iterator itContents = jsInput->AsObject().find(L"contents");
if (itContents != jsInput->AsObject().end() && itContents->second != NULL && itContents->second->IsArray())
{
jsArray = itContents->second->AsArray();
}
std::wcout << "[" << std::endl;
JSONArray::iterator it = jsArray.begin();
JSONArray::iterator itEnd = jsArray.end();
for (; it != itEnd; ++it)
{
JSONValue* jsValue = *it;
if (jsValue->IsObject())
{
jsValue->AsObject();
JSONObject::const_iterator itObj = jsValue->AsObject().begin();
JSONObject::const_iterator itObjEnd = jsValue->AsObject().end();
for (; itObj != itObjEnd; ++itObj)
{
std::wstring strValue = itObj->second->AsString();
std::wcout << L"{" << itObj->first << L":" << strValue << L"}" << std::endl;
}
}
else if (jsValue->IsString())
{
std::wstring strValue = jsValue->AsString();
std::wcout << strValue << std::endl;
}
else if (jsValue->IsNumber())
{
double dValue = jsValue->AsNumber();
std::wcout << dValue << std::endl;
}
//...
}
std::wcout << "]" << std::endl;
}
示例2: Load
bool ProjectBuildSettings::Load(const String& path)
{
SharedPtr<File> file(new File(context_, path));
if (!file->IsOpen())
return false;
SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
bool result = jsonFile->Load(*file);
file->Close();
if (!result)
return false;
JSONValue root = jsonFile->GetRoot();
if (!root.IsObject())
return false;
macBuildSettings_->Read(root);
windowsBuildSettings_->Read(root);
webBuildSettings_->Read(root);
androidBuildSettings_->Read(root);
iosBuildSettings_->Read(root);
return true;
}
示例3: getObjectFromArray
JSONObject Configuration::getObjectFromArray(const wstring& arrayName, const wstring& field) {
JSONValue *c = json[arrayName];
if (c == NULL || c->IsObject() == FALSE) {
throw new exception();
}
JSONObject arr = c->AsObject();
JSONValue *val = arr[field];
if (val == NULL || val->IsObject() == FALSE) {
throw new exception();
}
return val->AsObject();
}
示例4: ProcessHaxeDecl
void JSBModule::ProcessHaxeDecl()
{
// Haxe declarations
JSONValue root = moduleJSON_->GetRoot();
JSONValue decl = root.GetChild("haxe_decl");
if (decl.IsObject())
{
Vector<String> childNames = decl.GetChildNames();
for (unsigned j = 0; j < childNames.Size(); j++)
{
String classname = childNames.At(j);
JSBClass* klass = GetClass(classname);
if (!klass)
{
ErrorExit("Bad Haxe decl class");
}
JSONValue classdecl = decl.GetChild(classname);
for (unsigned k = 0; k < classdecl.GetSize(); k++)
{
klass->AddHaxeDecl(classdecl.GetString(k));
}
}
}
}
示例5: 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;
}
示例6: RunExperiments
void RunExperiments(ifstream &input, ofstream &output) {
// Read input file
input.seekg(0, ios::end);
size_t input_length = input.tellg();
input.seekg(0, ios::beg);
char * input_content = new char[input_length+1];
input.read(input_content, input_length);
input_content[input_length] = 0;
map<string, fnptr> ®isteredExperiments = RegisterExperiment("", NULL);
cout << "Registered experiments: " << endl;
for(map<string, fnptr>::iterator it = registeredExperiments.begin(); it != registeredExperiments.end(); ++it)
cout << "\t- " << it->first << endl;
// Create JSON object
JSONValue *root = JSON::Parse(input_content);
delete [] input_content;
// Iterate over each object
if (!root->IsObject()) {
cerr << "Error, the input file does not contain objects." << endl;
return;
}
cout << endl;
cout << "* Running Experiments" << endl;
output << "{" << endl;
// This is a vector of <sdt::wstring, JSONValue>
JSONObject objects = root->AsObject();
Timer overall_time;
for(JSONObject::iterator it = objects.begin(); it != objects.end(); ++it) {
string tmp((it->first).begin(), (it->first).end());
output << "experiment_name: \"" << tmp << "\"" << endl;
if (registeredExperiments.count(tmp) == 0) {
cout << "\tExperiment " << tmp << " is not registered." << endl;
output << "result: \"error\"" << endl;
} else {
cout << "\tRunning experiment " << tmp << endl;
Timer experiment_time;
wstring result = registeredExperiments[tmp](it->second->Stringify());
experiment_time.stop();
string tmp_result(result.begin(), result.end());
output << "result: " << tmp_result << endl;
output << "experiment_time:" << experiment_time.elapsedTime() << endl;
}
}
overall_time.stop();
output << "overall_time:" << overall_time.elapsedTime() << endl;
output << GetSystemInformation();
output << "}" << endl;
}
示例7: Read
void WebBuildSettings::Read(JSONValue& parent)
{
JSONValue json = parent.Get("WebBuildSettings");
if (!json.IsObject())
return;
appName_ = json.Get("appName").GetString();
packageName_ = json.Get("packageName").GetString();
companyName_ = json.Get("companyName").GetString();
productName_ = json.Get("productName").GetString();
}
示例8: ProcessExcludes
void JSBModule::ProcessExcludes()
{
// excludes
JSONValue root = moduleJSON_->GetRoot();
JSONValue excludes = root.GetChild("excludes");
if (excludes.IsObject())
{
Vector<String> childNames = excludes.GetChildNames();
for (unsigned j = 0; j < childNames.Size(); j++)
{
String classname = childNames.At(j);
JSBClass* klass = GetClass(classname);
if (!klass)
{
ErrorExit("Bad exclude klass");
}
JSONValue classexcludes = excludes.GetChild(classname);
Vector<String> functionNames = classexcludes.GetChildNames();
for (unsigned k = 0; k < functionNames.Size(); k++)
{
JSONValue sig = classexcludes.GetChild(functionNames[k]);
if (!sig.IsArray())
{
ErrorExit("Bad exclude defintion");
}
Vector<String> values;
for (unsigned x = 0; x < sig.GetSize(); x++)
{
values.Push(sig.GetString(x));
}
JSBFunctionSignature* fe = new JSBFunctionSignature(functionNames[k], values);
klass->AddFunctionExclude(fe);
}
}
}
}
示例9: getIntFromArray
INT Configuration::getIntFromArray(const wstring& arrayName, const wstring& field) {
JSONObject::const_iterator iter;
JSONValue *c = json[arrayName];
if (c == NULL || c->IsObject() == FALSE) {
throw new exception();
}
JSONObject arr = c->AsObject();
JSONValue *val = arr[field];
if (val == NULL || val->IsNumber() == FALSE) {
throw new exception();
}
return static_cast<INT>(val->AsNumber());
}
示例10: createJSON
bool HGESurrogate::createJSON(JSONValue& json, bool firstResponder)
{
bool didCreate = 0;
if (json.IsObject()) {
if (firstResponder) {
JSONValue& substitution = json[JSON_SUBSTITUTION_DECLARATION];
if (!substitution.IsUndefined())
{
this->carry(substitution);
didCreate = !0;
firstResponder = 0;
}
}
}
return didCreate;
}
示例11: notif_thread
unsigned WINAPI notif_thread(LPVOID)
{
JSONValue *j = fql_query(L"select+title_text%2c+href%2c+icon_url+from+notification+where+recipient_id+%3d+me()+and+is_unread");
if(j && j->IsObject())
{
JSONObject obj = j->AsObject();
JSONArray data = obj[L"data"]->AsArray();
for(JSONArray::const_iterator i = data.begin();i != data.end();++i)
{
if(!((*i)->IsObject()))
continue;
JSONObject i_obj = (*i)->AsObject();
wstring href, title_text;
href = i_obj[L"href"]->AsString();
title_text = i_obj[L"title_text"]->AsString();
display_notif(wstring(L"Facebook Notification"), title_text, href);
}
delete j;
}
return 0;
}
示例12: AddJsonStr
std::wstring CTestJSON::AddJsonStr( const std::wstring& strJsonStr )
{
/*
SimpleJson 库插入是非常麻烦的事情。
JSONValue对象有智能指针的功能,会给你析构掉它所包含的JSON对象
而JSON的as....函数,返回的是const类型的引用,如果是array类型,那么是JSONValue*的浅拷贝
对Parse的返回值实行delete之后,JSONValue又会再delete一次,于是出现多次析构的错误
所以必须保证,要么只有JSONValue对象去执行析构,要么只有主动的delete Parse的返回值。
对于插入来说,这种逻辑会带来麻烦。定义了一个JSONValue,浅拷贝了parse返回值的一部分json对象,
然后JSONValue析构了浅拷贝的JSONValue*,先对Parse的返回值则很难做处理,如果delete,则多析构了JSON对象,
如果不delete,则Parse内部new的map内存没有被析构。
解决办法有两种:
1、不要定义JSONValue对象,而是定义JSONValue引用,因为我要往JSONValue里插值,所以必须用到const_cast。
2、递归拷贝出JSONValue*里的字符串格式的JSON对象,然后再Parse之后进入新JSONObj,
保证新、旧对象分离。
*/
JSONValue* jsInput = JSON::Parse(strJsonStr.c_str());
if (jsInput == NULL || !jsInput->IsObject())
{
return L"";
}
std::wstring strRet;
JSONObject jsObjNew;
JSONObject::const_iterator it = jsInput->AsObject().begin();
JSONObject::const_iterator itEnd = jsInput->AsObject().end();
for (; it != itEnd; ++it)
{
std::wstring strFirst = it->first.c_str();
std::wstring strSecond = it->second->Stringify().c_str();
JSONValue* pTemp = JSON::Parse(strSecond.c_str());
jsObjNew[strFirst] = pTemp;
}
jsObjNew[L"Love"] = new(std::nothrow)JSONValue(L"is Happiness");
JSONValue jsValueNew = jsObjNew;
strRet = jsValueNew.Stringify();
return strRet;
}
示例13: 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;
}
示例14:
JNIEXPORT void JNICALL Java_tv_ouya_sdk_android_CallbacksRequestPurchase_CallbacksRequestPurchaseOnSuccess(JNIEnv* env, jobject thiz, jstring jsonData)
{
//LOGI("***********Java_tv_ouya_sdk_android_CallbacksRequestPurchase_CallbacksRequestPurchaseOnSuccess***********");
std::string strJsonData = env->GetStringUTFChars(jsonData, NULL);
//char buffer[256];
//sprintf(buffer, "Java_tv_ouya_sdk_android_CallbacksRequestPurchase_CallbacksRequestPurchaseOnSuccess: Returned to C: %s", strJsonData.c_str());
//LOGI(buffer);
// Parse example data
JSONValue* value = JSON::Parse(strJsonData.c_str());
if (value == NULL)
{
LOGI("Parsing JSON Failed");
return;
}
if (!value->IsObject())
{
LOGI("Parsing JSON Failed: Not an object");
return;
}
// Retrieve the main object
JSONValue data = value->AsObject();
OuyaSDK::Product product;
product.ParseJSON(&data);
CallbacksRequestPurchase* callback = CallbackSingleton::GetInstance()->m_callbacksRequestPurchase;
if (callback)
{
callback->OnSuccess(product);
}
}
示例15: ReadPreferences
bool AEEditorPrefs::ReadPreferences(VariantMap& engineParameters)
{
String path = GetPreferencesPath();
JSONValue prefs;
LoadPreferences(prefs);
if (!prefs.IsObject() || !prefs["editorWindow"].IsObject())
{
if (!CreateDefaultPreferences(path, prefs))
return false;
}
JSONValue& editorWindow = prefs["editorWindow"];
engineParameters["WindowPositionX"] = editorWindow["x"].GetUInt();
engineParameters["WindowPositionY"] = editorWindow["y"].GetUInt();
engineParameters["WindowWidth"] = editorWindow["width"].GetUInt();
engineParameters["WindowHeight"] = editorWindow["height"].GetUInt();
engineParameters["WindowMaximized"] = editorWindow["maximized"].GetBool();
return true;
}