我想将IgniteCache中的值转换为JSON 举个例子,我很感激。
ex)
CacheConfiguration<String, String> cache = new CacheConfigruation<>();
Ignite ignite = Ignition.start();
IgniteCache<String, String> igniteCache =
ignite.getOrCreateCache(cache);
igniteCache.put("key1","value");
igniteCache.put("key2","value");
如何转换为json?
答案 0 :(得分:2)
CacheConfiguration<String, JSONObject> cache = new CacheConfigruation<>();
Ignite ignite = Ignition.start();
IgniteCache<String, JSONObject> igniteCache = ignite.getOrCreateCache(cache);
igniteCache.put("key1","value");
igniteCache.put("key2","value");
答案 1 :(得分:1)
Ignite是键值缓存,具有许多其他功能,如SQL,但首先它是缓存,您可以将JSON保存到缓存或任何其他东西。您可以使用像gson这样的lib将对象转换为json,然后将其保存为点燃,这里有一个示例:https://github.com/google/gson/blob/master/UserGuide.md#TOC-Primitives-Examples
答案 2 :(得分:0)
CacheConfiguration<String, JSONObject> cache = new CacheConfigruation<>();
Ignite ignite = Ignition.start();
IgniteCache<String, JSONObject> igniteCache = ignite.getOrCreateCache(cache);
JSONObject json = new JSONObject();
json.put("key1",value);
igniteCache.put("key",new JSONObject().put("key2",json));
在上面的代码中,我在其他JSONObject中添加了JSONObject,并将其作为“密钥”存储在密钥的Cache中,如果你必须提取上面的JSONObject,你将得到关注ans。
JSONObject output = igniteCache.get("key");
output : {
key2 :
{
key1 : value
}
}