示例代码
//demo.hpp
#pragma once
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
#include "json.hpp"
#include <string>
using json = nlohmann::json;
using eosio::contract;
using eosio::multi_index;
using eosio::print;
class[[eosio::contract]] demo : public contract
{
public:
using contract::contract;
[[eosio::action]] void demoaction();
};
//demo.cpp
#include "demo.hpp"
using json = nlohmann::json;
// ACTION
void demo::demoaction()
{
json demoInfo = R"(
{
"demoInfo": {
"hello": "world"
}
}
)"_json;
std::string demoInfoString = demoInfo.dump();
json demoInfoJson = json::parse(demoInfoString);
print("It worked\n");
}
EOSIO_DISPATCH(demo, (demoaction))
json.hpp从https://github.com/nlohmann/json/releases 下载并将其放在同一目录中demo.hpp。
参考
https://github.com/EOSIO/eosio.cdt/issues/110
版权属于:区块链中文技术社区 / 转载原创者
本文链接:https://bcskill.com/index.php/archives/575.html
相关技术文章仅限于相关区块链底层技术研究,禁止用于非法用途,后果自负!本站严格遵守一切相关法律政策!