应用程序使用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。
感谢您的帮助。
答案 0 :(得分:1)
您可以使用Jackson JSON序列化程序以适当的格式将HashMap或POJO转换为JSON。 E.g:
Map<String, Object> mapMatchingJsonStructure = ...
OutputStream out = // where you want to write the output
new ObjectMapper().writeValue(out, mapMatchingJsonStructure);
Cayenne在cayenne-wocompat中有一个plist解析器。这与您不太相关,因为您已经解析了plist。但我以为我会提到。