std::string JsonUtils::SearchTabJson(const SearchTabDefinition& search_tab) { // The JSON publishes the MapsSearchAdapter for all search url's, since the // JS processing code is the same for all JSON based clients. std::string url = search_tab.url.utf8().data(); url = ReplaceString(url, kEarthClientSearchAdapter, kMapsSearchAdapter); // Collect the arg fields into a vector. std::vector<std::string> arg_array_entries; for (int i = 0; i < static_cast<int>(search_tab.fields.size()); ++i) { const SearchTabDefinition::Field& field = search_tab.fields[i]; std::map<std::string, std::string> arg_field_map; arg_field_map["screenLabel"] = Quoted(field.label); arg_field_map["urlTerm"] = Quoted(field.key); std::string arg_entry = JsonObject(arg_field_map); arg_array_entries.push_back(arg_entry); } std::string args_array = JsonArray(arg_array_entries); // Create the map of field name-value pairs for the output JSON. std::map<std::string, std::string> field_map; field_map["tabLabel"] = Quoted(search_tab.label); field_map["url"] = Quoted(url); field_map["args"] = args_array; return JsonObject(field_map); }
JsonObject JsonObject::getChild(const char* key) const { if (!isObject()) return JsonObject(); InternalString str = {key, (int)strlen(key)}; const Impl::map::const_iterator it = impl->objChildren.find(str); if (it == impl->objChildren.end()) return JsonObject(); JsonObject child; child.impl = &(*it).second; child.shouldDelete = false; return child; }
std::string JsonUtils::MapLayerJson(const MapLayerJSConfig::Layer& layer, const DbHeader& db_header, const std::string& locale) { // Get the legend for the specified locale. const LegendLocale& legend_locale = layer.legend_.GetLegendLocale(locale); // Create the map of field name-value pairs for the output JSON. std::string icon_name = "icons/" + legend_locale.icon.GetValue().LegendHref(); bool is_imagery = (layer.type_ == MapLayerJSConfig::Layer::Imagery); double opacity = 1.0; std::map<std::string, std::string> field_map; field_map["id"] = Itoa(layer.channel_id_); field_map["version"] = Itoa(layer.index_version_); field_map["label"] = Quoted(legend_locale.name.GetValue()); field_map["icon"] = Quoted(icon_name); field_map["initialState"] = JsonUtils::JsonBool(legend_locale.isChecked.GetValue()); field_map["isPng"] = JsonUtils::JsonBool(!is_imagery); field_map["opacity"] = DoubleToString(opacity); field_map["requestType"] = Quoted( MapLayerRequestType(db_header.is_mercator_, layer)); // TODO: add new locale fields // opacity (needs locale entry and ui) // look_at (needs ui) std::string lookAt(legend_locale.lookAt.GetValue().utf8()); field_map["lookAt"] = JsonUtils::LookAtJson(lookAt); return JsonObject(field_map); }
JsonObject JsonObject::object(const QString& key) const { checkContains(key); QJsonValue value = o.value(key); if ( ! value.isObject()) wrongType("object", key); return JsonObject(value.toObject()); }
void PostData::clearAction() { PostData &self = *this; self["action"]["type"].setValue(); self["action"]["modifier"].setValue(); self["param"] = JsonObject(); }
JsonObject JsonObject::get_object(const std::string &name) { int pos = positions[name]; if (pos <= start) { return JsonObject(); // empty object } jsin->seek(pos); return jsin->get_object(); }
JsonObject JsonObject::getChild(int index) const { if (!isArray() || index < 0 || index >= (int)impl->arrChildren.size()) return JsonObject(); JsonObject child; child.impl = &impl->arrChildren[index]; child.shouldDelete = false; return child; }
PostData::PostData(const QString &id, const QString &secret) { JsonObject o; o["device"] = JsonObject(); o["device"]["id"] = id; o["device"]["secret"] = secret; o["client"] = JsonObject(); o["client"]["card"]; o["client"]["pin"]; o["action"] = JsonObject(); o["action"]["type"]; o["action"]["modifier"]; o["param"] = JsonObject(); setValue(o); }
std::string JsonUtils::GELayerJson(const LayerConfig& layer, const std::string& locale) { LocaleConfig locale_config = layer.GetLocale(locale); // Create the map of field name-value pairs for the output JSON. std::map<std::string, std::string> field_map; field_map["id"] = Quoted(layer.asset_uuid_); field_map["label"] = Quoted(locale_config.name_.GetValue()); field_map["description"] = Quoted(locale_config.desc_.GetValue()); field_map["isInitiallyOn"] = JsonUtils::JsonBool(locale_config.is_checked_.GetValue()); field_map["isExpandable"] = JsonUtils::JsonBool(layer.isExpandable); field_map["isEnabled"] = JsonUtils::JsonBool(layer.isEnabled); field_map["isVisible"] = JsonUtils::JsonBool(layer.isVisible); std::string lookAt(locale_config.look_at_.GetValue().utf8()); field_map["lookAt"] = JsonUtils::LookAtJson(lookAt); return JsonObject(field_map); }
std::string JsonUtils::GEJsonBuffer( const std::string& database_url, const std::string& host_domain, const std::string& protocol, const std::vector<RasterDBRootGenConfig::Layer>& raster_layers, const std::vector<LayerConfig>& vector_layers, const std::string& locale) { std::string layers_json = JsonUtils::GELayersJson(raster_layers, vector_layers, locale); // Create the map of field name-value pairs for the output JSON. std::map<std::string, std::string> field_map; field_map["dbType"] = Quoted(std::string("gedb")); field_map["serverUrl"] = Quoted(database_url); field_map["isAuthenticated"] = JsonUtils::JsonBool(protocol.compare("https") == 0); field_map["layers"] = layers_json; return JsonObject(field_map); }
std::string JsonUtils::GERasterLayerJson( const RasterDBRootGenConfig::Layer& layer, const std::string& locale) { LegendLocale locale_config = layer.legend_.GetLegendLocale(locale); // Create the map of field name-value pairs for the output JSON. std::map<std::string, std::string> field_map; field_map["id"] = Quoted(layer.asset_uuid_); field_map["label"] = Quoted(locale_config.name.GetValue()); field_map["description"] = Quoted(locale_config.desc.GetValue()); field_map["isInitiallyOn"] = JsonUtils::JsonBool(locale_config.isChecked.GetValue()); field_map["isExpandable"] = JsonUtils::JsonBool(false); field_map["isEnabled"] = JsonUtils::JsonBool(true); field_map["isVisible"] = JsonUtils::JsonBool(true); std::string lookAt(locale_config.lookAt.GetValue().utf8()); field_map["lookAt"] = JsonUtils::LookAtJson(lookAt); return JsonObject(field_map); }
std::string JsonUtils::LookAtJson(const std::string& lookAtSpec) { if (lookAtSpec.empty()) return Quoted(std::string("none")); // LookAtSpec format is : // longitude|latitude|altitude|... // we only care for these 3. std::vector<std::string> tokens; TokenizeString(lookAtSpec, tokens, "|"); double altitude = strtod(tokens[2].c_str(), NULL); int zoomLevel = AltitudeToZoomLevel(altitude); // Create the map of field name-value pairs for the output JSON. std::map<std::string, std::string> field_map; field_map["lat"] = tokens[1]; field_map["lng"] = tokens[0]; field_map["zoom"] = Itoa(zoomLevel); field_map["altitude"] = DoubleToString(altitude); return JsonObject(field_map); }
std::string JsonUtils::MapsJsonBuffer( const std::string& database_url, const std::string& host_domain, const std::string& protocol, const std::vector<MapLayerJSConfig::Layer>& layers, const DbHeader& db_header, const std::string& locale) { std::string layers_json = JsonUtils::MapLayersJson(layers, db_header, locale); // Create the map of field name-value pairs for the output JSON. std::map<std::string, std::string> field_map; field_map["dbType"] = Quoted(std::string("gemap")); field_map["serverUrl"] = Quoted(database_url); field_map["useGoogleLayers"] = JsonUtils::JsonBool(db_header.use_google_imagery_); field_map["isAuthenticated"] = JsonUtils::JsonBool(database_url.find("https") == 0); field_map["projection"] = Quoted(std::string(db_header.is_mercator_ ? "mercator" : "flat")); field_map["layers"] = layers_json; return JsonObject(field_map); }
JsonObject JsonIn::get_object() { return JsonObject(this); }
/** * @brief Parse a string that contains a JSON object. * @param [in] text The JSON text string. * @return a JSON object. */ JsonObject JSON::parseObject(std::string text) { return JsonObject(cJSON_Parse(text.c_str())); } // parseObject
/** * @brief Get the named object value from the object. * @param [in] name The name of the object property. * @return The object value from the object. */ JsonObject JsonObject::getObject(std::string name) { cJSON *node = cJSON_GetObjectItem(m_node, name.c_str()); return JsonObject(node); } // getObject
/** * @brief Create an empty JSON object. * @return An empty JSON object. */ JsonObject JSON::createObject() { return JsonObject(cJSON_CreateObject()); } // createObject
/** * @brief Get the indexed object value from the array. * @param [in] item The index of the array to retrieve. * @return The object value at the given index. */ JsonObject JsonArray::getObject(int item) { cJSON *node = cJSON_GetArrayItem(m_node, item); return JsonObject(node); } // getObject
void JsonObject::buildObject(JsonObject &parent, json_object *obj) { enum json_type type; json_object_object_foreach(obj, key, val) { type = json_object_get_type(val); switch (type) { case json_type_object: { JsonObject child; JsonObject::buildObject(child, val); parent.push_back(key, child); } break; case json_type_array: { json_object *jArray = val; std::vector<JsonObject> objArray; std::vector<std::string> strArray; std::vector<bool> boolArray; std::vector<int> intArray; int arraylen = json_object_array_length(jArray); json_object *jValue; for (int i = 0; i < arraylen; i++) { jValue = json_object_array_get_idx(jArray, i); type = json_object_get_type(jValue); switch (type) { case json_type_string: { std::string value = json_object_get_string(jValue); strArray.push_back(value); } break; case json_type_boolean: { bool value = (bool)json_object_get_boolean(jValue); boolArray.push_back(value); } break; case json_type_int: { int value = json_object_get_int(jValue); intArray.push_back(value); } break; case json_type_object: { JsonObject child; JsonObject::buildObject(child, jValue); objArray.push_back(child); } break; default:break; } } JsonObject child; if (!strArray.empty()) { child = JsonObject(strArray); } else if (!boolArray.empty()) { child = JsonObject(boolArray); } else if (!intArray.empty()) { child = JsonObject(intArray); } else if (!objArray.empty()) { child = JsonObject(objArray); } parent.push_back(key, child); } break; case json_type_boolean: { bool value = (bool)json_object_get_boolean(val); parent.push_back(key, value); } break; case json_type_int: { int value = json_object_get_int(val); parent.push_back(key, value); } break; case json_type_string: { std::string value = json_object_get_string(val); parent.push_back(key, value.c_str()); } break; default: break; }; }
TSharedRef<class FJsonObject> FVariantData::ToJson() const { TSharedRef<FJsonObject> JsonObject(new FJsonObject()); const TCHAR* TypeStr = TEXT("Type"); const TCHAR* ValueStr = TEXT("Value"); JsonObject->SetStringField(TypeStr, EOnlineKeyValuePairDataType::ToString(Type)); switch (Type) { case EOnlineKeyValuePairDataType::Int32: { int32 FieldValue; GetValue(FieldValue); JsonObject->SetNumberField(ValueStr, (double)FieldValue); break; } case EOnlineKeyValuePairDataType::Float: { float FieldValue; GetValue(FieldValue); JsonObject->SetNumberField(ValueStr, (double)FieldValue); break; } case EOnlineKeyValuePairDataType::String: { FString FieldValue; GetValue(FieldValue); JsonObject->SetStringField(ValueStr, FieldValue); break; } case EOnlineKeyValuePairDataType::Bool: { bool FieldValue; GetValue(FieldValue); JsonObject->SetBoolField(ValueStr, FieldValue); break; } case EOnlineKeyValuePairDataType::Int64: { JsonObject->SetStringField(ValueStr, ToString()); break; } case EOnlineKeyValuePairDataType::Double: { double FieldValue; GetValue(FieldValue); JsonObject->SetNumberField(ValueStr, (double)FieldValue); break; } case EOnlineKeyValuePairDataType::Empty: case EOnlineKeyValuePairDataType::Blob: default: { JsonObject->SetStringField(ValueStr, FString()); break; } }; return JsonObject; }