本文整理汇总了C++中JSONValue::AsNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONValue::AsNumber方法的具体用法?C++ JSONValue::AsNumber怎么用?C++ JSONValue::AsNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONValue
的用法示例。
在下文中一共展示了JSONValue::AsNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getInt
INT Configuration::getInt(const wstring& field) {
JSONValue *c = json[field];
if (c == NULL || c->IsNumber() == FALSE) {
throw new exception();
}
return static_cast<INT>(c->AsNumber());
}
示例3: 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());
}