简体   繁体   English

将plist格式的文本转换为json格式

[英]Convert plist format text to json format

Application uses Apache Cayenne. 应用程序使用Apache Cayenne。

I receive a string in the following format. 我收到以下格式的字符串。 This string is available for me in HashMap format as well. 该字符串也可以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*")]}]}

I would like to covert the above string to json format like below 我想将上面的字符串转换为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*" } ] } ] }

I may have to create POJOs and loop through the Map to to achieve this. 我可能必须创建POJO并遍历Map才能实现此目的。 Perhaps some recursion is involved. 也许涉及一些递归。

I eventually feed the above json to jquery querybuilder. 我最终将上述json传递给jquery querybuilder。

Thank you for your help. 谢谢您的帮助。

You can use Jackson JSON serializer to convert your HashMap or POJO to JSON in appropriate format. 您可以使用Jackson JSON序列化器将HashMap或POJO转换为适当格式的JSON。 Eg: 例如:

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

Also Cayenne has a plist parser in cayenne-wocompat . Cayenne在cayenne-wocompat中也有一个plist解析器。 This is less relevant to you, as you already have your plist parsed. 这与您无关紧要,因为您已经解析了plist。 But I thought I'd mention. 但是我想我提一提。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM