std::vector<StarredFile> StarredFile::listFromJSON(const json_t *json, json_error_t *error) { std::vector<StarredFile> files; for (size_t i = 0; i < json_array_size(json); i++) { StarredFile file = fromJSON(json_array_get(json, i), error); files.push_back(file); } return files; }
std::vector<ServerRepo> ServerRepo::listFromJSON(const json_t *json, json_error_t *error) { std::vector<ServerRepo> repos; for (size_t i = 0; i < json_array_size(json); i++) { ServerRepo repo = fromJSON(json_array_get(json, i), error); repos.push_back(repo); } return repos; }
std::vector<SeafEvent> SeafEvent::listFromJSON(const json_t *json, json_error_t *error) { std::vector<SeafEvent> events; for (size_t i = 0; i < json_array_size(json); i++) { SeafEvent event = fromJSON(json_array_get(json, i), error); events.push_back(event); } return events; }
TransformMatrix TransformMatrix::fromJSON(std::string json) { Json::Value root; Json::Reader reader; if (!reader.parse(json, root)) { std::stringstream ss; ss << "Unable to decode matrix from: " << json; throw ss.str(); } return fromJSON(root); }
Colour::Colour(const std::string& str) { try { //First attempt to load as JSON string json jval = json::parse(str); fromJSON(jval); } catch (std::exception& e) { //Not valid JSON, assume other string value fromString(str); } }
OAuth10Credentials OAuth10Credentials::fromFile(const std::string& credentialsFile) { OAuth10Credentials credentials; try { credentials = fromJSON(ofJson::parse(ofBufferFromFile(credentialsFile))); } catch (const std::exception& exception) { ofLogError("Credentials::fromFile") << exception.what(); } return credentials; }
void Project::fromJSON(const QJsonObject& project) { mEventTypes.clear(); mName = project["name"].toString(); if (!project["lastOpenedTimeline"].toString().isEmpty()) mLastOpenedTimeline = QDir(root()).filePath(project["lastOpenedTimeline"].toString()); const QJsonArray& eventTypes = project["eventTypes"].toArray(); for (auto it = eventTypes.begin(); it != eventTypes.end(); it++) { auto eventType = std::make_shared<EventType>(); eventType->fromJSON(it->toObject()); mEventTypes.push_back(eventType); } }
LaunchPoint* LaunchPoint::fromFile(ApplicationDescription* appDesc, const std::string& filePath) { char* jsonStr = readFile(filePath.c_str()); if (!jsonStr) return 0; // infer the launchpoint ID from the filename gchar* fileName = g_path_get_basename(filePath.c_str()); LaunchPoint* lp = fromJSON(appDesc, jsonStr, fileName); delete [] jsonStr; g_free(fileName); return lp; }
Value Value::fromDynamic(JSContextRef ctx, const folly::dynamic& value) { // JavaScriptCore's iOS APIs have their own version of this direct conversion. // In addition, using this requires exposing some of JSC's private APIs, // so it's limited to non-apple platforms and to builds that use the custom JSC. // Otherwise, we use the old way of converting through JSON. #if USE_FAST_FOLLY_DYNAMIC_CONVERSION // Defer GC during the creation of the JSValue, as we don't want // intermediate objects to be collected. // We could use JSValueProtect(), but it will make the process much slower. JSDeferredGCRef deferGC = JSDeferGarbageCollection(ctx); // Set a global lock for the whole process, // instead of re-acquiring the lock for each operation. JSLock(ctx); JSValueRef jsVal = Value::fromDynamicInner(ctx, value); JSUnlock(ctx); JSResumeGarbageCollection(ctx, deferGC); return Value(ctx, jsVal); #else auto json = folly::toJson(value); return fromJSON(String(ctx, json.c_str())); #endif }
bool File::save() { Client client; client.addHeader("Content-Type", contentType_); client.setPayload(body_); JSON response; try { client.post("files/" + localFileName_); response = client.getJSONResponse(); } catch (const exception &e) { return false; } fromJSON(response); return true; }
File::File(const JSON &obj) { fromJSON(obj); }
Pointer::Pointer(const JSON &obj) { fromJSON(obj); }
Colour::Colour(json& jvalue, GLubyte red, GLubyte grn, GLubyte blu, GLubyte alpha) : r(red), g(grn), b(blu), a(alpha) { fromJSON(jvalue); }