【问题标题】:Java JSON Parser with Regex [closed]带有正则表达式的 Java JSON 解析器 [关闭]
【发布时间】:2018-02-01 12:15:44
【问题描述】:

我收到来自服务器的 JSON 响应。 JSON 里面有异常信息。 我需要对其进行解析以检测发生的异常并确定是哪一个。

JSON 示例:

【问题讨论】:

  • 你有什么问题?

标签: java json regex


【解决方案1】:

我找到了我需要的解决方案

Pattern errorCodePattern = Pattern.compile("\"code\"\\s*:\\s*\"([^,]*)\",");
Pattern messagePattern = Pattern.compile("\"message\"\\s*:\\s*\"([^,]*)\",");
Pattern statusPattern = Pattern.compile("\"status\"\\s*:\\s*\"(FAILURE)\"");
 Matcher errorCodeMatcher = errorCodePattern.matcher(response);
Matcher messageMatcher = messagePattern.matcher(response);
Matcher statusMatcher = statusPattern.matcher(response); 

Java JSON Parser Example with Regex

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    相关资源
    最近更新 更多