JsonObject* SamiAccessToken::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pAccess_tokenKey = new JsonString(L"access_token"); pJsonObject->Add(pAccess_tokenKey, toJson(getPAccessToken(), "String", "")); JsonString *pRefresh_tokenKey = new JsonString(L"refresh_token"); pJsonObject->Add(pRefresh_tokenKey, toJson(getPRefreshToken(), "String", "")); JsonString *pExpire_inKey = new JsonString(L"expire_in"); pJsonObject->Add(pExpire_inKey, toJson(getPExpireIn(), "Integer", "")); JsonString *pExpires_inKey = new JsonString(L"expires_in"); pJsonObject->Add(pExpires_inKey, toJson(getPExpiresIn(), "Integer", "")); JsonString *pScopeKey = new JsonString(L"scope"); pJsonObject->Add(pScopeKey, toJson(getPScope(), "String", "array")); return pJsonObject; }
void toJson(json::ostream_writer_t& os, const QVariant& var) { QVariant::Type type = var.type(); switch(type) { case QVariant::Map: { const QVariantMap map = var.toMap(); os.object_start(); for (QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it) { os.new_string(it.key().toStdString().c_str()); toJson(os, it.value()); } os.object_end(); } break; case QVariant::List: case QVariant::StringList: { const QVariantList list = var.toList(); os.array_start(); for (int i = 0; i < list.size(); i++) { toJson(os, list.at(i)); } os.array_end(); } break; case QVariant::String: { os.new_string(var.toString().toStdString().c_str()); } break; case QVariant::Bool: { os.new_bool(var.toBool()); } break; default: if (var.canConvert< double >()) { os.new_double(var.toDouble()); break; } os.new_string("unsupported yet!"); break; } }
Json::Value imuToJson(const IMUData& sample, timestamp_t start_time) { Json::Value sampleEntry(Json::objectValue); sampleEntry["gyro"] = toJson(sample.gyro); sampleEntry["acc"] = toJson(sample.acc); sampleEntry["gyroAcc"] = toJson(sample.gyroAcc); sampleEntry["attitude"] = toJson(sample.attitude); sampleEntry["timestamp"] = ((sample.timestamp - start_time) / std::chrono::microseconds(1)); sampleEntry["debugData"] = sample.jsonDebugData; return sampleEntry; }
JsonObject* SamiAlgorithm::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pProblem_typeKey = new JsonString(L"problem_type"); pJsonObject->Add(pProblem_typeKey, toJson(getPProblemType(), "String", "")); JsonString *pObjectiveKey = new JsonString(L"objective"); pJsonObject->Add(pObjectiveKey, toJson(getPObjective(), "String", "")); return pJsonObject; }
JsonObject* SamiShipment::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pIdKey = new JsonString(L"id"); pJsonObject->Add(pIdKey, toJson(getPId(), "String", "")); JsonString *pNameKey = new JsonString(L"name"); pJsonObject->Add(pNameKey, toJson(getPName(), "String", "")); JsonString *pPriorityKey = new JsonString(L"priority"); pJsonObject->Add(pPriorityKey, toJson(getPPriority(), "Integer", "")); JsonString *pPickupKey = new JsonString(L"pickup"); pJsonObject->Add(pPickupKey, toJson(getPPickup(), "SamiStop", "")); JsonString *pDeliveryKey = new JsonString(L"delivery"); pJsonObject->Add(pDeliveryKey, toJson(getPDelivery(), "SamiStop", "")); JsonString *pSizeKey = new JsonString(L"size"); pJsonObject->Add(pSizeKey, toJson(getPSize(), "Integer", "array")); JsonString *pRequired_skillsKey = new JsonString(L"required_skills"); pJsonObject->Add(pRequired_skillsKey, toJson(getPRequiredSkills(), "String", "array")); JsonString *pAllowed_vehiclesKey = new JsonString(L"allowed_vehicles"); pJsonObject->Add(pAllowed_vehiclesKey, toJson(getPAllowedVehicles(), "String", "array")); return pJsonObject; }
/** * Expected input: * { * alg: "aes", * mode: "cbc", * key: key data, * iv: iv data (16 bytes), * input: data to encrypt or decrypt * } * * Good output: * { * output: data * } */ Json::Value AES::crypt(const std::string & algorithm, Json::Value & args, bool isEncrypt) { if (!args.isMember("key")) { throw std::string("key missing"); } if (!args.isMember("input")) { throw std::string("input missing"); } if (!args.isMember("iv")) { throw std::string("iv missing"); } if (!args.isMember("mode")) { throw std::string("mode missing"); } std::string modeString( gsecrypto::util::lowerCaseRemoveDashes(args["mode"].asString())); if ("cbc" != modeString) { throw std::string("Only CBC currently supported"); } DataTracker input; getData(args["input"], input); DataTracker result(input.dataLen); if (input.dataLen == 0) { Json::Value toReturn; toReturn["output"] = toJson(result); return toReturn; } DataTracker keyBytes; getData(args["key"], keyBytes); DataTracker iv; getData(args["iv"], iv); int mode = SB_AES_CBC; AESParams params(*this, SB_AES_CBC, SB_AES_128_BLOCK_BITS, false); AESKey key(params, keyBytes); AESContext context(params, key, mode, iv); context.crypt(input, result, isEncrypt); Json::Value toReturn; toReturn["output"] = toJson(result); return toReturn; }
Json::Value toJson(dev::eth::BlockInfo const& _bi, BlockDetails const& _bd, UncleHashes const& _us, Transactions const& _ts) { Json::Value res = toJson(_bi); if (_bi) { res["totalDifficulty"] = toJS(_bd.totalDifficulty); res["uncles"] = Json::Value(Json::arrayValue); for (h256 h: _us) res["uncles"].append(toJS(h)); res["transactions"] = Json::Value(Json::arrayValue); for (unsigned i = 0; i < _ts.size(); i++) res["transactions"].append(toJson(_ts[i], std::make_pair(_bi.hash(), i), (BlockNumber)_bi.number)); } return res; }
void ItemSerializer::toJson(std::ostream& out, const sserialize::Static::spatial::GeoShape& gs) const { sserialize::spatial::GeoShapeType gst = gs.type(); out << "{\"t\":" << gst << ",\"v\":"; switch(gst) { case sserialize::spatial::GS_POINT: { auto gp = gs.get<sserialize::spatial::GS_POINT>(); out << "[" << gp->lat() << "," << gp->lon() << "]"; } break; case sserialize::spatial::GS_WAY: case sserialize::spatial::GS_POLYGON: { auto gw = gs.get<sserialize::spatial::GS_WAY>(); out << "["; if (gw->size()) { auto it(gw->cbegin()), end(gw->cend()); sserialize::Static::spatial::GeoPoint gp(*it); out << "[" << gp.lat() << "," << gp.lon() << "]"; for(++it; it != end; ++it) { gp = *it; out << ",[" << gp.lat() << "," << gp.lon() << "]"; } } out << "]"; } break; case sserialize::spatial::GS_MULTI_POLYGON: { out << "{"; auto gmw = gs.get<sserialize::spatial::GS_MULTI_POLYGON>(); if (gmw->innerPolygons().size()) { out << "\"inner\":"; toJson(out, gmw->innerPolygons()); out << ","; } out << "\"outer\":"; toJson(out, gmw->outerPolygons()); out << "}"; } break; default: break; } out << "}"; }
Json::Value toJson(dev::eth::TransactionReceipt const& _tr, std::pair<h256, unsigned> _location, BlockNumber _blockNumber, Transaction const& _t) { Json::Value res; h256 h = _t.sha3(); res["transactionHash"] = toJS(h); res["transactionIndex"] = _location.second; res["blockHash"] = toJS(_location.first); res["blockNumber"] = _blockNumber; res["cumulativeGasUsed"] = toJS(_tr.gasUsed()); // TODO: check if this is fine res["gasUsed"] = toJS(_tr.gasUsed()); res["contractAddress"] = toJS(toAddress(_t.from(), _t.nonce())); res["logs"] = Json::Value(Json::arrayValue); for (unsigned i = 0; i < _tr.log().size(); i++) { LogEntry e = _tr.log()[i]; Json::Value l = toJson(e); l["type"] = "mined"; l["blockNumber"] = _blockNumber; l["blockHash"] = toJS(_location.first); l["logIndex"] = i; l["transactionHash"] = toJS(h); l["transactionIndex"] = _location.second; res["logs"].append(l); } return res; }
//------------------------------------------------------------------------------ // Name: toJson //------------------------------------------------------------------------------ QByteArray QJsonDocument::toJson(JsonFormat format) const { Q_UNUSED(format); if(isArray()) { QString s = toJson(array(), format); return s.toUtf8(); } if(isObject()) { QString s = toJson(object(), format); return s.toUtf8(); } return QByteArray(); }
JsonObject* SamiMeasurementValue::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pStart_timeKey = new JsonString(L"start_time"); pJsonObject->Add(pStart_timeKey, toJson(getPStartTime(), "Long", "")); JsonString *pValueKey = new JsonString(L"value"); pJsonObject->Add(pValueKey, toJson(getPValue(), "Float", "")); return pJsonObject; }
JsonObject* SamiStatus::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pCodeKey = new JsonString(L"code"); pJsonObject->Add(pCodeKey, toJson(getPCode(), "String", "")); JsonString *pInfoKey = new JsonString(L"info"); pJsonObject->Add(pInfoKey, toJson(getPInfo(), "String", "")); return pJsonObject; }
QVariant AnimationEditor::ImageTableModel::data(const QModelIndex &index, int role) const { if (role == Qt::DecorationRole || role == Qt::DisplayRole) { int r = index.row(); int c = index.column(); auto slide = m_model.Images[r]; switch (c) { case 0: { auto img = slide.Image; if (!m_pixMaps.contains(slide.Image.toJson())) { m_pixMaps[img.toJson()] = SpriteSheetManager::getPixmap(img, m_projectPath); } return m_pixMaps[slide.Image.toJson()]; } case 1: { auto spriteSheet = m_projectPath + slide.Image.SpriteSheet; spriteSheet = spriteSheet.mid(spriteSheet.lastIndexOf('/') + 1); spriteSheet = spriteSheet.mid(0, spriteSheet.size() - 5); return spriteSheet; } case 2: return slide.Interval; } } return QVariant(); }
/*! * \brief Generate JSON string from QVariant * \param data QVariant with data * \param indent Identation of new lines * \return JSON string with data */ QByteArray generate(const QVariant &data, int indent) { Q_UNUSED(indent); auto document = QJsonDocument::fromVariant(data); return document.toJson(QJsonDocument::Indented); }
void Canvas::drawLineTo(const QPoint &endPoint) { LayerPointer l = layers.selectedLayer(); if(l.isNull() || l->isLocked() || l->isHided()){ setCursor(Qt::ForbiddenCursor); return; } // setCursor(Qt::CrossCursor); updateCursor(brush_->width()); brush_->setSurface(l->imagePtr()); brush_->lineTo(endPoint); update(); QVariantMap start_j; start_j.insert("x", this->lastPoint.x()); start_j.insert("y", this->lastPoint.y()); QVariantMap end_j; end_j.insert("x", endPoint.x()); end_j.insert("y", endPoint.y()); QVariantMap map; map.insert("brush", QVariant(brushInfo())); map.insert("start", QVariant(start_j)); map.insert("end", QVariant(end_j)); map.insert("layer", QVariant(currentLayer())); map.insert("userid", QVariant(userId())); QVariantMap bigMap; bigMap.insert("info", map); bigMap.insert("action", "drawline"); QByteArray tmp = toJson(QVariant(bigMap)); emit sendData(tmp); }
JsonObject* SamiApiResponse::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pCodeKey = new JsonString(L"code"); pJsonObject->Add(pCodeKey, toJson(getPCode(), "Integer", "")); JsonString *pTypeKey = new JsonString(L"type"); pJsonObject->Add(pTypeKey, toJson(getPType(), "String", "")); JsonString *pMessageKey = new JsonString(L"message"); pJsonObject->Add(pMessageKey, toJson(getPMessage(), "String", "")); return pJsonObject; }
JsonObject* SamiInline_response_200_28::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pDataKey = new JsonString(L"data"); pJsonObject->Add(pDataKey, toJson(getPData(), "SamiVariable", "")); JsonString *pSuccessKey = new JsonString(L"success"); pJsonObject->Add(pSuccessKey, toJson(getPSuccess(), "Boolean", "")); return pJsonObject; }
JsonObject* SamiQuery::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pIncludeListKey = new JsonString(L"$includeList"); pJsonObject->Add(pIncludeListKey, toJson(getPIncludeList(), "String", "array")); JsonString *pIncludeKey = new JsonString(L"$include"); pJsonObject->Add(pIncludeKey, toJson(getPInclude(), "String", "array")); return pJsonObject; }
std::string ResourceHandler::toJsonString() { struct json_object * jobj = toJson(); std::string s = json_object_to_json_string(jobj); json_object_put(jobj); return s; }
JsonObject* SamiQueueBody::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pDocumentKey = new JsonString(L"document"); pJsonObject->Add(pDocumentKey, toJson(getPDocument(), "SamiQueue", "")); JsonString *pKeyKey = new JsonString(L"key"); pJsonObject->Add(pKeyKey, toJson(getPKey(), "String", "")); return pJsonObject; }
Json::Value toJson(dev::eth::LocalisedLogEntry const& _e) { Json::Value res; if (_e.isSpecial) res = toJS(_e.special); else { res = toJson(static_cast<dev::eth::LogEntry const&>(_e)); if (_e.mined) { res["type"] = "mined"; res["blockNumber"] = _e.blockNumber; res["blockHash"] = toJS(_e.blockHash); res["logIndex"] = _e.logIndex; res["transactionHash"] = toJS(_e.transactionHash); res["transactionIndex"] = _e.transactionIndex; } else { res["type"] = "pending"; res["blockNumber"] = Json::Value(Json::nullValue); res["blockHash"] = Json::Value(Json::nullValue); res["logIndex"] = Json::Value(Json::nullValue); res["transactionHash"] = Json::Value(Json::nullValue); res["transactionIndex"] = Json::Value(Json::nullValue); } } return res; }
JsonObject* SamiNATimeTableItem::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pIdKey = new JsonString(L"id"); pJsonObject->Add(pIdKey, toJson(getPId(), "Integer", "")); JsonString *pM_offsetKey = new JsonString(L"m_offset"); pJsonObject->Add(pM_offsetKey, toJson(getPMOffset(), "Integer", "")); return pJsonObject; }
JsonObject* SamiCategory::asJsonObject() { JsonObject *pJsonObject = new JsonObject(); pJsonObject->Construct(); JsonString *pIdKey = new JsonString(L"id"); pJsonObject->Add(pIdKey, toJson(getPId(), "Long", "")); JsonString *pNameKey = new JsonString(L"name"); pJsonObject->Add(pNameKey, toJson(getPName(), "String", "")); return pJsonObject; }
QByteArray NetworkPackage::serialize() const { //Object -> QVariant //QVariantMap variant; //variant["id"] = mId; //variant["type"] = mType; //variant["body"] = mBody; QVariantMap variant = qobject2qvariant(this); if (hasPayload()) { //qCDebug(KDECONNECT_CORE) << "Serializing payloadTransferInfo"; variant[QStringLiteral("payloadSize")] = payloadSize(); variant[QStringLiteral("payloadTransferInfo")] = mPayloadTransferInfo; } //QVariant -> json auto jsonDocument = QJsonDocument::fromVariant(variant); QByteArray json = jsonDocument.toJson(QJsonDocument::Compact); if (json.isEmpty()) { qCDebug(KDECONNECT_CORE) << "Serialization error:"; } else { /*if (!isEncrypted()) { //qCDebug(KDECONNECT_CORE) << "Serialized package:" << json; }*/ json.append('\n'); } return json; }
QString SimpleJsonDB::jsonString() { acquireWriteLock(); QString dbString = db->toJson(QMJsonFormat_Pretty, QMJsonSort_CaseSensitive); if (filterVmAndDomstoreKeys) { auto filteredValue = QMJsonValue::fromJson(dbString); if (filteredValue.isNull()) { qCritical("unable to convert db string to qmjsonvalue!"); exit(1); } if (!filteredValue->isObject()) { qCritical("db qmjsonvalue is not an object!"); exit(1); } filteredValue->toObject()->remove("vm"); filteredValue->toObject()->remove("dom-store"); dbString = filteredValue->toJson(QMJsonFormat_Pretty, QMJsonSort_CaseSensitive); } releaseWriteLock(); return dbString; }
Json::Value toJson(dev::eth::Transaction const& _t, bytes const& _rlp) { Json::Value res; res["raw"] = toJS(_rlp); res["tx"] = toJson(_t); return res; }
int main() { /* Found three mines in sweep 1 */ int i, no = 10; mine_t c = { -412.55, -929.15 }; mine_t *tmpMines = malloc(sizeof(mine_t)*no); for (i=0; i<no; i++) tmpMines[i] = c; sweep_t *sweep1 = malloc(sizeof(sweep_t)); sweep1->no = no; sweep1->mine_p = tmpMines; /* Convert to Json */ char *jsonString = toJson(sweep1); /* Convert to netstring */ char *netString = toNetString(jsonString); /* Print */ printf("jsonNetString: \"%s\"", netString); free(sweep1); free(tmpMines); free(jsonString); free(netString); return 0; }
void BattleToJson::onSendOut(int spot, int player, ShallowBattlePoke *pokemon, bool silent) { makeCommand("send"); map.insert("slot", player); map.insert("silent", silent); map.insert("pokemon", toJson(*pokemon)); }
void Canvas::drawPoint(const QPoint &point) { LayerPointer l = layers.selectedLayer(); if(l.isNull() || l->isLocked() || l->isHided()){ setCursor(Qt::ForbiddenCursor); return; } // setCursor(Qt::CrossCursor); updateCursor(brush_->width()); brush_->setSurface(l->imagePtr()); brush_->start(point); int rad = (brush_->width() / 2) + 2; update(QRect(lastPoint, point).normalized() .adjusted(-rad, -rad, +rad, +rad)); QVariantMap point_j; point_j.insert("x", point.x()); point_j.insert("y", point.y()); QVariantMap map; map.insert("brush", QVariant(brushInfo())); map.insert("layer", QVariant(currentLayer())); map.insert("point", QVariant(point_j)); map.insert("userid", QVariant(userId())); QVariantMap bigMap; bigMap.insert("info", map); bigMap.insert("action", "drawpoint"); QByteArray tmp = toJson(QVariant(bigMap)); emit sendData(tmp); }
std::string toJson(MessageWraper& obj){ char buffer[1024]; char* p = buffer; *p='{';p++; MessageWraper::CIter iter; MessageWraper::CObjIter objIter; bool begin = true; for(iter = obj.messages.begin();iter!=obj.messages.end();iter++){ if(!begin){ *p++=','; }else{ begin = false; } JSONObjectType type = obj.typeMap[iter->first]; if ((objIter=obj.innerObjects.find(iter->first)) != obj.innerObjects.end()) { addKVPair(p, iter->first.c_str(), toJson(*(objIter->second)).c_str(),true); } else { addKVPair(p, iter->first.c_str(), iter->second.c_str(),type==OBJECT||type==ARRAY); } p++; } *p++='}'; *p='\0'; return std::string(buffer); }