### Question:
Util { public static String extractBytePacketValueFromString(final String packetName, final String s) { if (packetName == null) { return EmptyString; } JsonParser jp = new JsonParser(); JsonElement je = null; try { je = jp.parse(s); }catch (Exception e) { Logger logger = LoggerFactory.getLogger("com.nhnent.eat.common.Util"); logger.error("packetName:{}\n, json:\n{}\n", packetName, s); logger.error(ExceptionUtils.getStackTrace(e)); } JsonElement foundElement= getValueOfVar(je, packetName); if(foundElement != null) { return foundElement.toString(); } else { return EmptyString; } } private  Util(); static void printMethods(final Class c); static String extractJsonVariableNameFromString(final String s); static String extractJsonVariableValueFromString(final String s); static String extractBytePacketValueFromString(final String packetName, final String s); static void extractGlobalVariable(final String s); static String applyVariable(HashMap<String, String> variableSet, final String s); static Class loadClassFromJarFile(final String pathToJar, final String apiClassName);  }### Answer:
@Test public void extractBytePacketValueFromString() throws Exception { String s = "{\n" + " \"unitMessage\": [\n" + " {\n" + " \"packetBytes\": {\n" + " \"[MSG]UserInfoReply\": {\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"; s= makeSimpleJson(s); String returned = Util.extractBytePacketValueFromString("packetBytes", s); System.out.println(returned); }
@Test public void test() throws Exception { String s = "{\n" + " \"id\": \"\",\n" + " \"payload\": \"\",\n" + " \"channelId\": \"\"\n" + "}"; s= makeSimpleJson(s); String returned = Util.extractBytePacketValueFromString("payload",s); System.out.println(returned); }
@Test public void test2() throws Exception { String s = "{\n" + " \"payload\": \"CAI=\"\n" + "}"; String returned = Util.extractBytePacketValueFromString("payload",s); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(s); JsonObject jo = je.getAsJsonObject(); System.out.println(jo.get("payload")); }
@Test public void test4() throws Exception { String s = "{\n" + " \"[RPS]RPSGamePayloadForRoomOption\": {\n" + " \"option\": \"@@joinRoomOption\"\n" + " }\n" + " }"; String returned = Util.extractBytePacketValueFromString("data", s); System.out.println(returned); }