【问题标题】:Convert plist format text to json format将 plist 格式文本转换为 json 格式
【发布时间】:2016-06-08 17:03:17
【问题描述】:

应用程序使用 Apache Cayenne。

我收到以下格式的字符串。我也可以使用 HashMap 格式的这个字符串。

{And=[(effectiveDate >= Tue Sep 01 00:00:00 EDT 2015), {And=[(loanType = 2), {Or=[{And=[{Not=[(specialFeaturesString like "*003* ")]}, {Not=[(specialFeaturesString like "*007*")]}]}, (specialFeaturesString like "*007*")]}, (specialFeaturesString like "*808*")]}]}

我想把上面的字符串转换成下面这样的json格式

{ "condition": "AND", "rules": [ { "id": "eDate", "field": "eDate", "type": "date", "input": "text", "operator": "greater_or_equal", "value": "2015/09/01" }, { "condition": "AND", "rules": [ { "id": "loanType", "field": "loanType", "type": "string", "input": "text", "operator": "equal", "value": "2" }, { "condition": "OR", "rules": [ { "id": "specialFeatureText", "field": "specialFeatureText", "type": "string", "input": "text", "operator": "equal", "value": "*707*" }, { "condition": "AND", "rules": [ { "id": "specialFeatureText", "field": "specialFeatureText", "type": "string", "input": "text", "operator": "not_equal", "value": "*003*" }, { "id": "specialFeatureText", "field": "specialFeatureText", "type": "string", "input": "text", "operator": "not_equal", "value": "*007*" } ] } ] }, { "id": "specialFeatureText", "field": "specialFeatureText", "type": "string", "input": "text", "operator": "equal", "value": "*808*" } ] } ] }

我可能必须创建 POJO 并循环遍历 Map 来实现这一点。可能涉及到一些递归。

我最终将上述 json 提供给 jquery querybuilder。

感谢您的帮助。

【问题讨论】:

    标签: json collections hashmap plist apache-cayenne


    【解决方案1】:

    您可以使用 Jackson JSON 序列化程序将您的 HashMap 或 POJO 转换为适当格式的 JSON。例如:

    Map<String, Object> mapMatchingJsonStructure = ...
    OutputStream out = // where you want to write the output
    new ObjectMapper().writeValue(out, mapMatchingJsonStructure);
    

    Cayenne 在cayenne-wocompat 中也有一个 plist 解析器。这与您不太相关,因为您已经解析了 plist。但我想我会提到。

    【讨论】:

      猜你喜欢
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2020-08-30
      • 2015-12-17
      相关资源
      最近更新 更多