本文整理汇总了Java中net.arnx.jsonic.JSON.decode方法的典型用法代码示例。如果您正苦于以下问题:Java JSON.decode方法的具体用法?Java JSON.decode怎么用?Java JSON.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.arnx.jsonic.JSON
的用法示例。
在下文中一共展示了JSON.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeAddressCorresponGroup
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private List<DistTemplateGroup> decodeAddressCorresponGroup(String value, boolean to) {
if (StringUtils.isEmpty(value)) {
return new ArrayList<DistTemplateGroup>();
}
List<DistTemplateGroup> addresses =
(List<DistTemplateGroup>) JSON.decode(value, getMappingType());
Long dgOrderNo = 0L;
for (DistTemplateGroup dg : addresses) {
dg.setDistributionType(to ? DistributionType.TO : DistributionType.CC);
dg.setOrderNo(dgOrderNo++);
List<DistTemplateUser> users = dg.getUsers();
if (users == null) {
continue;
}
Long duOrderNo = 0L;
for (DistTemplateUser du : users) {
du.setDistTemplateGroupId(dg.getId());
du.setOrderNo(duOrderNo++);
}
}
return addresses;
}
示例2: testJSONToObject2
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
@Test
public void testJSONToObject2() throws Exception {
String json =
"[{corresponGroupId:\"1\",users:[{empNo:\"ZZA01\"},{empNo:\"ZZA02\"}]}," +
"{corresponGroupId:\"2\",users:[{empNo:\"ZZA03\"},{empNo:\"ZZA04\"}]}]";
List<CorresponGroupUserMapping> mappings =
(List<CorresponGroupUserMapping>)
JSON.decode(json,
getClass().getField("m").getGenericType());
assertEquals(2, mappings.size());
for (CorresponGroupUserMapping m : mappings) {
System.out.println(m);
}
}
示例3: getInitialData
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
/**
* 初期化データを取得します。
* <pre>
* クラスと同一パスにある<TableClassName>.data.jsonというファイルを読み込みます。
* </pre>
* @return 初期化データ。
* @throws Exception 例外。
*/
@SuppressWarnings("unchecked")
public List<Map<String, Object>> getInitialData() throws Exception {
List<Map<String, Object>> list = null;
Class<?> cls = this.getClass();
InputStream is = cls.getResourceAsStream("data/" + cls.getSimpleName() + ".data.json");
if (is != null) {
try {
String json = new String(FileUtil.readInputStream(is), DataFormsServlet.getEncoding());
list = (List<Map<String, Object>>) JSON.decode(json);
} finally {
is.close();
}
}
return list;
}
示例4: loadDtoFromResource
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
private <DTO> DTO loadDtoFromResource(String path, Class<DTO> dtoClass) throws MloException {
DTO dto = null;
InputStream inputStream = null;
URL url = ResourceUtil.getResource(path);
try {
try {
inputStream = url.openStream();
dto = JSON.decode(inputStream, dtoClass);
} finally {
if (inputStream != null) {
inputStream.close();
inputStream = null;
}
}
} catch (IOException e) {
LOG.error("Unexpected situation.", e);
throw new InternalException("Unexpected situation.", e);
}
return dto;
}
示例5: loadProfile
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
/**
* Load profiles from specified directory.
* This method must be called once before language detection.
*
* @param json_profiles all json-encoded profiles
* @throws LangDetectException Can't open profiles(error code = {@link ErrorCode#FileLoadError})
* or profile's format is wrong (error code = {@link ErrorCode#FormatError})
*/
public void loadProfile(final List<String> json_profiles) throws LangDetectException {
final int langsize = json_profiles.size();
if (langsize < 2)
throw new LangDetectException(ErrorCode.NeedLoadProfileError, "Need more than 2 profiles");
int index = 0;
for (final String json : json_profiles) {
try {
final LangProfile profile = JSON.decode(json, LangProfile.class);
addProfile(profile, index, langsize);
++index;
} catch (JSONException e) {
throw new LangDetectException(ErrorCode.FormatError, "profile format error");
}
}
}
示例6: onReadText
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
@Override
public void onReadText(final WebSocketContext context,
final String key, final String message) throws IOException {
final Map<String, Object> m = JSON.decode(message);
final Object ping = m.get("ping");
final Object messageId = m.get("messageId");
if (messageId != null) {
if (ping != null) {
final Optional<String> latestId = IMBoxMessageIdManager.messageId(key);
if (latestId.isPresent()) {
final Map<String, Object> id = new HashMap<>();
id.put("messageId", latestId.get());
id.put("pong", ping);
final String pong = JSON.encode(id);
synchronized (context) {
final PrintWriter out = context.startTextMessage();
out.print(pong); // initialize browser's memo
out.close();
}
}
} else { // set the latest messageId at first time
final String mid = messageId instanceof String ? (String) messageId : "";
IMBoxMessageIdManager.messageId(key, Optional.of(mid));
}
}
}
示例7: loadProfile
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
/**
* Load profiles from specified directory.
* This method must be called once before language detection.
*
* @param profileDirectory profile directory path
* @throws LangDetectException Can't open profiles(error code = {@link ErrorCode#FileLoadError})
* or profile's format is wrong (error code = {@link ErrorCode#FormatError})
*/
public static void loadProfile(List<String> json_profiles) throws LangDetectException {
int index = 0;
int langsize = json_profiles.size();
if (langsize < 2)
throw new LangDetectException(ErrorCode.NeedLoadProfileError, "Need more than 2 profiles");
for (String json: json_profiles) {
try {
LangProfile profile = JSON.decode(json, LangProfile.class);
addProfile(profile, index, langsize);
++index;
} catch (JSONException e) {
throw new LangDetectException(ErrorCode.FormatError, "profile format error");
}
}
}
示例8: onMessage
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
@OnMessage
public void onMessage(String message) {
RequestToGameExecutorTransferObject[] transferRequests = JSON.decode(message,
RequestToGameExecutorTransferObject[].class);
if (transferRequests == null || transferRequests.length == 0) {
log.warn("request is empty.");
return;
}
GameMessenger messenger = GameExecutorManager.getInstance()
.getGameExecutor(processId).getMessenger();
Arrays.asList(transferRequests).forEach(request -> {
if (request == null || request.getSConstructor() == null
|| request.getSConstructor().getExpression() == null) {
log.error("request is invalid {}.", request);
return;
}
messenger.sendMessage(request.makeInstance(processId.getValue()));
});
}
示例9: onMessage
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
@OnMessage
public String onMessage(String query, Session session) {
try {
FilterQuery filter = JSON.decode(query, FilterQuery.class);
Logs.filter.debug("update filter[{}]: {}", session.getId(), JSON.encode(filter));
_sessions.put(session, filter);
} catch (JSONException e) {
return "failed " + e.getMessage();
}
return "updated";
}
示例10: getDtoChangesJson
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
/**
* NaEF Restful API から DtoChanges JSON を取得する
*
* @param tx ターゲットとなるトランザクション ID
* @param time ターゲットとなる時間
* @return DtoChanges JSON
*/
public static Map<String, Object> getDtoChangesJson(TransactionId.W tx, DateTime time) throws IOException {
URL url = getDtoChangesUri(tx, time);
Map<String, Object> res;
URLConnection conn = url.openConnection();
try (InputStream is = conn.getInputStream()) {
res = JSON.decode(is);
}
return res;
}
示例11: toReqAttrs
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
public static Map<String, Object> toReqAttrs(HttpServletRequest req, String type, String id) throws ApiException {
final Map<String, Object> reqAttrs;
if (req.getMethod().equals(HttpMethod.POST) || req.getMethod().equals(HttpMethod.PUT)) {
try {
reqAttrs = JSON.decode(req.getInputStream());
} catch (IOException e) {
throw new BadRequest("API-02402", "不正なフォーマットです.");
}
} else {
reqAttrs = new LinkedHashMap<>();
}
// HEADER
Collections.list(req.getHeaderNames())
.forEach(name -> reqAttrs.put(CmdBuilderProcessor.PREFIX_HEADER + name, req.getHeader(name)));
// QUERY
Optional.ofNullable(req.getQueryString()).ifPresent(queries -> {
Arrays.stream(queries.split("&")).forEach(q -> {
String[] splited = q.split("=");
if (splited.length >= 2) {
reqAttrs.put(CmdBuilderProcessor.PREFIX_URI_QUERY + splited[0], splited[1]);
}
});
});
// PATH
if (type != null) reqAttrs.put(CmdBuilderProcessor.PREFIX_URI_PATH + "type", type);
if (id != null) reqAttrs.put(CmdBuilderProcessor.PREFIX_URI_PATH + "id", id);
return reqAttrs;
}
示例12: assertNode
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
public static Map<String, Object> assertNode(Response res, String nodeName) {
Map<String, Object> actual = JSON.decode(res.readEntity(String.class));
Map<String, Object> expected = nodeAttrs(nodeName);
expected.entrySet()
.forEach(e -> {
String key = e.getKey();
assertTrue(actual.containsKey(key));
assertEquals(e.getValue(), actual.get(key));
});
return actual;
}
示例13: assertLink
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
public static Map<String, Object> assertLink(Response res, String name, String port1, String port2) {
Map<String, Object> actual = JSON.decode(res.readEntity(String.class));
assertEquals(name, actual.get("name"));
List<Map<String, String>> memberPorts = (List<Map<String, String>>) actual.get("member_ports");
long ports = memberPorts.stream().filter(p -> {
String id = p.get("id");
return id.equals(port1) || id.equals(port2);
}).count();
assertEquals(2, memberPorts.size());
assertEquals(2, ports);
return actual;
}
示例14: testJSONToObject
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
@Test
public void testJSONToObject() {
String json = "[{\"1\":[\"ZZA01\",\"ZZA02\"]},{\"2\":[\"ZZA03\",\"ZZA04\"]}]";
List<Map<Long, List<String>>> list =
(List<Map<Long, List<String>>>) JSON.decode(json, List.class);
assertEquals(2, list.size());
for (Map<Long, List<String>> entry : list) {
System.out.println(entry);
}
}
示例15: getUserRegistConf
import net.arnx.jsonic.JSON; //导入方法依赖的package包/类
/**
* ユーザ登録関連設定を取得します。
*/
public void getUserRegistConf() {
// ユーザ登録ページ関連設定
LoginInfoForm.setUserRegistPage(this.getServletContext().getInitParameter("user-regist-page"));
UserRegistForm.setUserEnablePage(this.getServletContext().getInitParameter("user-enable-page"));
String conf = this.getServletContext().getInitParameter("user-regist-page-config");
Map<String, Object> m = JSON.decode(conf);
log.debug("m.class=" + m.getClass().getName());
log.debug("conf=" + m.toString());
UserRegistForm.setConfig(m);
// メール関連設定。
MailSender.setJndiPrefix(this.getServletContext().getInitParameter("jndi-prefix"));
MailSender.setMailSessionName(this.getServletContext().getInitParameter("mail-session"));
MailSender.setMailFrom(this.getServletContext().getInitParameter("mail-from"));
}