0

应用程序使用 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。

谢谢您的帮助。

4

1 回答 1

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。但我想我会提到。

于 2016-02-26T07:05:51.280 回答