本文整理汇总了C++中JSONNode::as_array方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONNode::as_array方法的具体用法?C++ JSONNode::as_array怎么用?C++ JSONNode::as_array使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONNode
的用法示例。
在下文中一共展示了JSONNode::as_array方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadContactsInfo
//[{"username":"echo123", "firstname" : "Echo \/ Sound Test Service", "lastname" : null, "avatarUrl" : null, "mood" : null, "richMood" : null, "displayname" : null, "country" : null, "city" : null},...]
void CSkypeProto::LoadContactsInfo(const NETLIBHTTPREQUEST *response)
{
if (response == NULL)
return;
JSONNode root = JSONNode::parse(response->pData);
if (!root)
return;
const JSONNode &items = root.as_array();
for (size_t i = 0; i < items.size(); i++)
{
const JSONNode &item = items.at(i);
if (!item)
break;
std::string skypename = item["username"].as_string();
MCONTACT hContact = AddContact(skypename.c_str());
if (hContact)
{
UpdateProfileCountry(item, hContact);
UpdateProfileCity(item, hContact);
UpdateProfileStatusMessage(item, hContact);
}
}
}
示例2: LoadContactsAuth
void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response)
{
if (response == NULL)
return;
JSONNode root = JSONNode::parse(response->pData);
if (!root)
return;
const JSONNode &items = root.as_array();
for (size_t i = 0; i < items.size(); i++)
{
const JSONNode &item = items.at(i);
if (!item)
break;
std::string skypename = item["sender"].as_string();
std::string reason = item["greeting"].as_string();
time_t eventTime = IsoToUnixTime(item["event_time_iso"].as_string().c_str());
MCONTACT hContact = AddContact(skypename.c_str());
if (hContact)
{
time_t lastEventTime = db_get_dw(hContact, m_szModuleName, "LastAuthRequestTime", 0);
if (lastEventTime < eventTime)
{
db_set_dw(hContact, m_szModuleName, "LastAuthRequestTime", eventTime);
delSetting(hContact, "Auth");
DB_AUTH_BLOB blob(hContact, NULL, NULL, NULL, skypename.c_str(), reason.c_str());
PROTORECVEVENT pre = { 0 };
pre.timestamp = time(NULL);
pre.lParam = blob.size();
pre.szMessage = blob;
ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
}
}
}
}
示例3: TestInspectors
void TestSuite::TestInspectors(void){
UnitTest::SetPrefix("TestInspectors.cpp - Inspectors");
JSONNode test = JSONNode(JSON_NULL);
#ifdef JSON_CASTABLE
assertEquals(test.as_string(), JSON_TEXT(""));
assertEquals(test.as_int(), 0);
assertEquals(test.as_float(), 0.0f);
assertEquals(test.as_bool(), false);
#endif
test = 15.5f;
assertEquals(test.type(), JSON_NUMBER);
#ifdef JSON_CASTABLE
assertEquals(test.as_string(), JSON_TEXT("15.5"));
#endif
assertEquals(test.as_int(), 15);
assertEquals(test.as_float(), 15.5f);
#ifdef JSON_CASTABLE
assertEquals(test.as_bool(), true);
#endif
test = 0.0f;
assertEquals(test.type(), JSON_NUMBER);
#ifdef JSON_CASTABLE
assertEquals(test.as_string(), JSON_TEXT("0"));
#endif
assertEquals(test.as_int(), 0);
assertEquals(test.as_float(), 0.0f);
#ifdef JSON_CASTABLE
assertEquals(test.as_bool(), false);
#endif
test = true;
assertEquals(test.type(), JSON_BOOL);
#ifdef JSON_CASTABLE
assertEquals(test.as_string(), JSON_TEXT("true"));
assertEquals(test.as_int(), 1);
assertEquals(test.as_float(), 1.0f);
#endif
assertEquals(test.as_bool(), true);
test = false;
assertEquals(test.type(), JSON_BOOL);
#ifdef JSON_CASTABLE
assertEquals(test.as_string(), JSON_TEXT("false"));
assertEquals(test.as_int(), 0);
assertEquals(test.as_float(), 0.0f);
#endif
assertEquals(test.as_bool(), false);
#ifdef JSON_CASTABLE
test.cast(JSON_NODE);
#else
test = JSONNode(JSON_NODE);
#endif
assertEquals(test.type(), JSON_NODE);
assertEquals(test.size(), 0);
test.push_back(JSONNode(JSON_TEXT("hi"), JSON_TEXT("world")));
test.push_back(JSONNode(JSON_TEXT("hello"), JSON_TEXT("mars")));
test.push_back(JSONNode(JSON_TEXT("salut"), JSON_TEXT("france")));
assertEquals(test.size(), 3);
TestSuite::testParsingItself(test);
#ifdef JSON_CASTABLE
JSONNode casted = test.as_array();
#ifdef JSON_UNIT_TEST
assertNotEquals(casted.internal, test.internal);
#endif
assertEquals(casted.type(), JSON_ARRAY);
assertEquals(test.type(), JSON_NODE);
assertEquals(test.size(), 3);
assertEquals(casted.size(), 3);
TestSuite::testParsingItself(casted);
#endif
UnitTest::SetPrefix("TestInspectors.cpp - Location");
try {
#ifdef JSON_CASTABLE
assertEquals(casted.at(0), JSON_TEXT("world"));
assertEquals(casted.at(1), JSON_TEXT("mars"));
assertEquals(casted.at(2), JSON_TEXT("france"));
assertEquals(casted.at(0).name(), JSON_TEXT(""));
assertEquals(casted.at(1).name(), JSON_TEXT(""));
assertEquals(casted.at(2).name(), JSON_TEXT(""));
#endif
assertEquals(test.at(0), JSON_TEXT("world"));
assertEquals(test.at(1), JSON_TEXT("mars"));
assertEquals(test.at(2), JSON_TEXT("france"));
assertEquals(test.at(0).name(), JSON_TEXT("hi"));
assertEquals(test.at(1).name(), JSON_TEXT("hello"));
assertEquals(test.at(2).name(), JSON_TEXT("salut"));
} catch (std::out_of_range){
FAIL("exception caught");
}
try {
assertEquals(test.at(JSON_TEXT("hi")), JSON_TEXT("world"));
assertEquals(test.at(JSON_TEXT("hello")), JSON_TEXT("mars"));
assertEquals(test.at(JSON_TEXT("salut")), JSON_TEXT("france"));
//.........这里部分代码省略.........