2017-01-01 3 views
0

appengine에서 memcache를 사용하고 있습니다. 내가 memcache에에서 문자열을 얻고 JSON 개체 만들려고 해요 지금appengine에서 memcach에서 문자열을 가져 오는 방법 - java

private static CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();; 
private static Cache cache = cacheFactory.createCache(Collections.emptyMap());; 
String data = "{\name\": \"jim\"}"; 
cache.put("1234", data); 

:

JSONObject dataObj = new JSONObject(cache.get("1234")); // log => {name: "john"} 

이 잘 나를 위해 작동을하고, 내가 예상 JSON 얻을 나는 JSON 문자열을 삽입 ->{name: "john"}.

이제 json을 만들기 전에 데이터를 가져오고 있습니다.

Object myData = cache.get("1234"); 
JSONObject dataObj = new JSONObject(myData); // log => {"bytes":[123,34,110,97,109,101,34,58,34,106,111,104,110,34,125],"empty":false} 

지금 내가 바이트 개체에서 데이터를 수신하고 ->{bytes: [12,..],empty: false}

무슨 일이야? 예상되는 행동이 없습니까?

나는 memcach-console에 값이 확인 저장할 때주의 할 편집 ->{name: "john"}

답변

1

대신

Object myData = cache.get("1234"); 

가, 그런데

String myData = (String) cache.get("1234"); 

시도 App Engine 다음 코드를 사용하고 있습니다 :

MemcacheService memcache = MemcacheServiceFactory.getMemcacheService(); 
memcache.put("1234", object); 
String myData = (String) memcache.get("1234"); 
+0

감사합니다! 그것은 나를 위해 일했다!! – dina

관련 문제