本文整理汇总了C++中JSONArray类的典型用法代码示例。如果您正苦于以下问题:C++ JSONArray类的具体用法?C++ JSONArray怎么用?C++ JSONArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSONArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetInterpolationMethod
bool ValueAnimation::LoadJSON(const JSONValue& source)
{
valueType_ = VAR_NONE;
eventFrames_.Clear();
String interpMethodString = source.Get("interpolationmethod").GetString();
InterpMethod method = (InterpMethod)GetStringListIndex(interpMethodString.CString(), interpMethodNames, IM_LINEAR);
SetInterpolationMethod(method);
if (interpolationMethod_ == IM_SPLINE)
splineTension_ = source.Get("splinetension").GetFloat();
// Load keyframes
JSONArray keyFramesArray = source.Get("keyframes").GetArray();
for (unsigned i = 0; i < keyFramesArray.Size(); i++)
{
const JSONValue& val = keyFramesArray[i];
float time = val.Get("time").GetFloat();
Variant value = val.Get("value").GetVariant();
SetKeyFrame(time, value);
}
// Load event frames
JSONArray eventFramesArray = source.Get("eventframes").GetArray();
for (unsigned i = 0; i < eventFramesArray.Size(); i++)
{
const JSONValue& eventFrameVal = eventFramesArray[i];
float time = eventFrameVal.Get("time").GetFloat();
unsigned eventType = eventFrameVal.Get("eventtype").GetUInt();
VariantMap eventData = eventFrameVal.Get("eventdata").GetVariantMap();
SetEventFrame(time, StringHash(eventType), eventData);
}
return true;
}
示例2: delete
CJSONElement::~CJSONElement()
{
if (m_type == TYPESTRING)
{
delete (string*)m_data.m_ptr;
}
else if (m_type == TYPEMAP)
{
JSONMap* map = (JSONMap*)m_data.m_ptr;
for (JSONMap::iterator it = map->begin(); it != map->end(); it++)
delete it->second;
delete (JSONMap*)m_data.m_ptr;
}
else if (m_type == TYPEARRAY)
{
JSONArray* array = (JSONArray*)m_data.m_ptr;
for (JSONArray::iterator it = array->begin(); it != array->end(); it++)
delete *it;
delete (JSONArray*)m_data.m_ptr;
}
delete m_error;
}
示例3: 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;
}
示例4: LoadJSON
bool UnknownComponent::LoadJSON(const JSONValue& source, bool setInstanceDefault)
{
useXML_ = true;
xmlAttributes_.Clear();
xmlAttributeInfos_.Clear();
binaryAttributes_.Clear();
JSONArray attributesArray = source.Get("attributes").GetArray();
for (unsigned i = 0; i < attributesArray.Size(); i++)
{
const JSONValue& attrVal = attributesArray.At(i);
AttributeInfo attr;
attr.mode_ = AM_FILE;
attr.name_ = attrVal.Get("name").GetString();
attr.type_ = VAR_STRING;
if (!attr.name_.Empty())
{
String attrValue = attrVal.Get("value").GetString();
attr.defaultValue_ = String::EMPTY;
xmlAttributeInfos_.Push(attr);
xmlAttributes_.Push(attrValue);
}
}
// Fix up pointers to the attributes after all have been read
for (unsigned i = 0; i < xmlAttributeInfos_.Size(); ++i)
xmlAttributeInfos_[i].ptr_ = &xmlAttributes_[i];
return true;
}
示例5: bday_thread
unsigned WINAPI bday_thread(LPVOID)
{
SYSTEMTIME st;
GetSystemTime(&st);
wostringstream q;
q << L"SELECT+name%2c+profile_url+from+user+where+uid+in+(select+uid2+from+friend+where+uid1+%3d+me())+and+strpos(birthday_date%2c%22";
q << (st.wMonth);
q << L"%2f";
q << (st.wDay);
q << L"%22)%3e%3d0";
wstring fql = q.str();
JSONValue *j = fql_query(fql.c_str());
if(j)
{
JSONObject obj = j->AsObject();
JSONArray data = (obj[L"data"] ? obj[L"data"]->AsArray(): JSONArray());
for(JSONArray::const_iterator i = data.begin();i != data.end(); ++i)
{
JSONObject i_obj = (*i)->AsObject();
wstring name = i_obj[L"name"]->AsString();
name += L" ma urodziny!";
wstring url = i_obj[L"profile_url"]->AsString();
display_notif(wstring(L"Facebook Urodziny"), name, url);
}
delete j;
}
return 0;
}
示例6: assert
void EntityIdentifier::parseCategoryDefinition(JSONObject *data, int packID) {
QString category;
if (data->has("category"))
category = data->at("category")->asString();
else
category = "Unknown";
QColor catcolor;
if (data->has("catcolor")) {
QString colorname = data->at("catcolor")->asString();
catcolor.setNamedColor(colorname);
assert(catcolor.isValid());
} else { // use hashed by name instead
quint32 hue = qHash(category);
catcolor.setHsv(hue % 360, 255, 255);
}
addCategory(qMakePair(category, catcolor));
if (data->has("entity")) {
JSONArray *entities = dynamic_cast<JSONArray *>(data->at("entity"));
int len = entities->length();
for (int e = 0; e < len; e++)
parseEntityDefinition(dynamic_cast<JSONObject *>(entities->at(e)),
category, catcolor, packID);
}
}
示例7: createJSONGeometry
JSONObject* WriteVisitor::createJSONMorphGeometry(osgAnimation::MorphGeometry* morphGeometry, osg::Object* parent)
{
if(!parent) {
parent = morphGeometry;
}
JSONObject* jsonGeometry = createJSONGeometry(morphGeometry, parent);
JSONArray* targetList = new JSONArray;
osgAnimation::MorphGeometry::MorphTargetList mTargetList = morphGeometry->getMorphTargetList();
typedef osgAnimation::MorphGeometry::MorphTargetList::iterator TargetIterator;
for(TargetIterator ti = mTargetList.begin(); ti != mTargetList.end(); ti++) {
osgAnimation::MorphGeometry::MorphTarget *morphTarget = &(*ti);
JSONObject *jsonGeometryObject = new JSONObject;
if(osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(morphTarget->getGeometry())) {
geometry->setPrimitiveSetList(osg::Geometry::PrimitiveSetList()); //delete unused drawArray
jsonGeometryObject->getMaps()["osg.Geometry"] = createJSONGeometry(geometry);
targetList->asArray()->getArray().push_back(jsonGeometryObject);
}
}
jsonGeometry->getMaps()["MorphTargets"] = targetList;
return jsonGeometry;
}
示例8: api_hdd_handler
void api_hdd_handler(const shared_ptr<restbed::Session> session)
{
Hdd *hdd;
JSONArray devices;
JSONObject obj;
JSONObject deviceData;
JSONValue *output;
double hddTotal;
double hddUsage;
vector<string> hddDevices;
hdd = Hdd::getInstance();
hddTotal = hdd->getTotalCapacity();
hddUsage = hdd->getUsedCapacity();
hddDevices = hdd->getListHardDrive();
obj[L"total"] = new JSONValue(hddTotal);
obj[L"usage"] = new JSONValue(hddUsage);
for (vector<string>::iterator it = hddDevices.begin(); it != hddDevices.end(); ++it)
{
deviceData[L"name"] = new JSONValue(s2ws(*it));
devices.push_back(new JSONValue(deviceData));
}
obj[L"devices"] = new JSONValue(devices);
output = new JSONValue(obj);
session->close(restbed::OK, ws2s(output->Stringify()), { { "Content-Type", "application/json" } });
}
示例9: OuyaPlugin_JSONArray_ToString
const char* OuyaPlugin_JSONArray_ToString(int jsonArray)
{
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "OuyaPlugin_JSONArray_ToString: jsonArray=%d", jsonArray);
#endif
std::map<int, JSONArray*>::const_iterator search = g_refJSONArray.find(jsonArray);
if (search != g_refJSONArray.end())
{
JSONArray* instance = search->second;
if (instance)
{
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "OuyaPlugin_JSONArray_ToString JSONArray reference is valid");
#endif
g_tempPluginString = instance->toString();
#if ENABLE_VERBOSE_LOGGING
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "OuyaPlugin_JSONArray_ToString jsonData=%s", g_tempPluginString.c_str());
#endif
return g_tempPluginString.c_str();
}
else
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "OuyaPlugin_JSONArray_ToString JSONArray reference is invalid");
}
}
else
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "OuyaPlugin_JSONArray_ToString failed to find JSONArray reference");
}
return "";
}
示例10: OuyaPlugin_JSONArray_Put
void OuyaPlugin_JSONArray_Put(int jsonArray, int index, int jsonObject)
{
std::map<int, JSONArray*>::const_iterator searchJSONArray = g_refJSONArray.find(jsonArray);
if (searchJSONArray == g_refJSONArray.end())
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "OuyaPlugin_JSONArray_Put JSONArray reference is invalid");
return;
}
std::map<int, JSONObject*>::const_iterator searchJSONObject = g_refJSONObject.find(jsonObject);
if (searchJSONObject == g_refJSONObject.end())
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "OuyaPlugin_JSONArray_Put JSONObject reference is invalid");
return;
}
JSONArray* instanceJSONArray = searchJSONArray->second;
if (!instanceJSONArray)
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "OuyaPlugin_JSONArray_Put JSONArray instance is invalid");
return;
}
JSONObject* instanceJSONObject = searchJSONObject->second;
if (!instanceJSONObject)
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "OuyaPlugin_JSONArray_Put JSONObject instance is invalid");
return;
}
instanceJSONArray->put(index, instanceJSONObject->GetInstance());
}
示例11: fromPoint
JSON::JSONArray JSON::fromPoint(const Point& point)
{
JSONArray array;
array.push_back(fromNumber(point.x()));
array.push_back(fromNumber(point.y()));
return array;
}
示例12: jsonValueToRapidJSON
void jsonValueToRapidJSON(JSONValue* value, rapidjson::Value& rapidValue, rapidjson::Document& document) {
JSONNull* nullValue = dynamic_cast<JSONNull*>(value);
if (nullValue) {
rapidValue.SetNull();
return;
}
JSONNumber* numberValue = dynamic_cast<JSONNumber*>(value);
if (numberValue) {
if (numberValue->canBeUInt64()) {
rapidValue.SetUint64(numberValue->getUInt64Value());
}
else if (numberValue->canBeInt64()) {
rapidValue.SetInt64(numberValue->getInt64Value());
}
else {
rapidValue.SetDouble(numberValue->getDoubleValue());
}
return;
}
JSONString* stringValue = dynamic_cast<JSONString*>(value);
if (stringValue) {
rapidValue.SetString(stringValue->getValue().c_str(), stringValue->getValue().size(), document.GetAllocator());
return;
}
JSONBool* boolValue = dynamic_cast<JSONBool*>(value);
if (boolValue) {
rapidValue.SetBool(boolValue->getValue());
return;
}
JSONArray* arrayValue = dynamic_cast<JSONArray*>(value);
if (arrayValue) {
rapidValue.SetArray();
std::vector<JSONValue::ref> values = arrayValue->getValues();
for (auto & value : values) {
rapidjson::Value obj;
jsonValueToRapidJSON(value.get(), obj, document);
rapidValue.PushBack(obj, document.GetAllocator());
}
return;
}
JSONObject* objectValue = dynamic_cast<JSONObject*>(value);
if (objectValue) {
rapidValue.SetObject();
typedef std::map<std::string, JSONValue::ref> ValuesMap;
ValuesMap values = objectValue->getValues();
for (auto & value : values) {
rapidjson::Value obj;
jsonValueToRapidJSON(value.second.get(), obj, document);
rapidjson::Value key;
key.SetString(value.first.c_str(), value.first.size(), document.GetAllocator());
rapidValue.AddMember(key, obj, document.GetAllocator());
}
return;
}
assert(false);
}
示例13: JSONArray
JSONArray* JSONArray::deepCopy() const {
JSONArray* result = new JSONArray();
const int size = this->size();
for (int i = 0; i < size; i++) {
result->add( JSONBaseObject::deepCopy( get(i) ) );
}
return result;
}
示例14: getResultClusterArray
bool Round::SystemGetNetworkInfoResponse::setClusters(LocalNode *node) {
JSONArray *clusterArray = getResultClusterArray();
JSONDictionary *jsonDict = new JSONDictionary();
SystemClusterInfoDict clusterInfoDict(jsonDict);
clusterInfoDict.setCluster(node);
clusterArray->add(jsonDict);
return true;
}
示例15: getMaps
JSONDrawArrayLengths::JSONDrawArrayLengths(osg::DrawArrayLengths& array)
{
getMaps()["First"] = new JSONValue<int>(array.getFirst());
getMaps()["Mode"] = getDrawMode(array.getMode());
JSONArray* jsonArray = new JSONArray;
for (unsigned int i = 0; i < array.size(); i++) {
jsonArray->getArray().push_back(new JSONValue<int>(array[i]));
}
getMaps()["ArrayLengths"] = jsonArray;
}