如何取消/销毁jsonarray密钥级别

x3naxklr  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(173)

我想知道如何取消或销毁一级json对象。这可以使用任何javaspring框架来完成,也可以为这个解决方案定义任何自定义功能。但需要保留“txtframearr”的inside数组中的数据,如下所示

  1. [
  2. {
  3. "txtFrameArr": {
  4. "CEPDuplicateTextFrame1": [
  5. {
  6. "marked": 1,
  7. "id_elems": [
  8. {
  9. "PS": "1",
  10. "OS": "1",
  11. "LS": "999",
  12. "name": "MARKETING_CLAIM",
  13. "IS": "1",
  14. "id": "CE-MARKETING_CLAIM-1_999_1_1"
  15. }
  16. ],
  17. "mapCordinates": [
  18. {
  19. "top": 468.645102009805,
  20. "left": 1053.47265625,
  21. "width": 30.8357511971699,
  22. "height": 132.963461384805
  23. },
  24. {
  25. "top": 513.29412308266,
  26. "left": 1067.05751323149,
  27. "width": 91.1260246588899,
  28. "height": 233.24627152016
  29. }
  30. ],
  31. "duplicate": 1,
  32. "content": "baby-dry pants",
  33. "txtframe_name": "ceptxtduplicateTF1-threaded1"
  34. }
  35. ]
  36. }
  37. },
  38. {
  39. "txtFrameArr": {
  40. "CEPTextFrame2": [
  41. {
  42. "marked": 1,
  43. "id_elems": [
  44. {
  45. "PS": "1",
  46. "OS": "1",
  47. "LS": "2",
  48. "name": "NET_CONTENT_STATEMENT",
  49. "IS": "1",
  50. "id": "CE-NET_CONTENT_STATEMENT-1_2_1_1"
  51. }
  52. ],
  53. "mapCordinates": [
  54. {
  55. "top": 22.599609375,
  56. "left": 740.23886611805,
  57. "width": 22.9008135909007,
  58. "height": 33.8291015625
  59. },
  60. {
  61. "top": -6.76171875,
  62. "left": 744.522124684196,
  63. "width": 15.4768987533043,
  64. "height": 9.2734375
  65. },
  66. {
  67. "top": -14.33203125,
  68. "left": 740.448785213874,
  69. "width": 22.2500000017299,
  70. "height": 6.88811848711339
  71. }
  72. ],
  73. "duplicate": 0,
  74. "content": "4단계 9-14 kg",
  75. "txtframe_name": "ceptxtCE-NET_CONTENT_STATEMENT-1_2_1_1-threaded2"
  76. }
  77. ]
  78. }
  79. },
  80. {
  81. "txtFrameArr": {
  82. "CEPTextFrame3": [
  83. {
  84. "marked": 1,
  85. "id_elems": [
  86. {
  87. "PS": "1",
  88. "OS": "1",
  89. "LS": "2",
  90. "name": "USAGE_INSTRUCTIONS",
  91. "IS": "4",
  92. "id": "CE-USAGE_INSTRUCTIONS-4_2_1_1"
  93. }
  94. ],
  95. "mapCordinates": [
  96. {
  97. "top": 215.9384765625,
  98. "left": -639.0234375,
  99. "width": 29.1552734375,
  100. "height": 55.2314453125
  101. }
  102. ],
  103. "duplicate": 0,
  104. "content": "위로 당기며 입혀줍니다",
  105. "txtframe_name": "ceptxtCE-USAGE_INSTRUCTIONS-4_2_1_1-3"
  106. }
  107. ]
  108. }
  109. }
  110. ]
  111. Supposed to be wanted like this by removing "txtFrameArr"
  112. [
  113. {
  114. "CEPDuplicateTextFrame1": [
  115. {
  116. "marked": 1,
  117. "id_elems": [
  118. {
  119. "PS": "1",
  120. "OS": "1",
  121. "LS": "999",
  122. "name": "MARKETING_CLAIM",
  123. "IS": "1",
  124. "id": "CE-MARKETING_CLAIM-1_999_1_1"
  125. }
  126. ],
  127. "mapCordinates": [
  128. {
  129. "top": 468.645102009805,
  130. "left": 1053.47265625,
  131. "width": 30.8357511971699,
  132. "height": 132.963461384805
  133. },
  134. {
  135. "top": 513.29412308266,
  136. "left": 1067.05751323149,
  137. "width": 91.1260246588899,
  138. "height": 233.24627152016
  139. }
  140. ],
  141. "duplicate": 1,
  142. "content": "baby-dry pants",
  143. "txtframe_name": "ceptxtduplicateTF1-threaded1"
  144. }
  145. ]
  146. },
  147. {
  148. "CEPTextFrame2": [
  149. {
  150. "marked": 1,
  151. "id_elems": [
  152. {
  153. "PS": "1",
  154. "OS": "1",
  155. "LS": "2",
  156. "name": "NET_CONTENT_STATEMENT",
  157. "IS": "1",
  158. "id": "CE-NET_CONTENT_STATEMENT-1_2_1_1"
  159. }
  160. ],
  161. "mapCordinates": [
  162. {
  163. "top": 22.599609375,
  164. "left": 740.23886611805,
  165. "width": 22.9008135909007,
  166. "height": 33.8291015625
  167. },
  168. {
  169. "top": -6.76171875,
  170. "left": 744.522124684196,
  171. "width": 15.4768987533043,
  172. "height": 9.2734375
  173. },
  174. {
  175. "top": -14.33203125,
  176. "left": 740.448785213874,
  177. "width": 22.2500000017299,
  178. "height": 6.88811848711339
  179. }
  180. ],
  181. "duplicate": 0,
  182. "content": "4단계 9-14 kg",
  183. "txtframe_name": "ceptxtCE-NET_CONTENT_STATEMENT-1_2_1_1-threaded2"
  184. }
  185. ]
  186. },
  187. {
  188. "CEPTextFrame3": [
  189. {
  190. "marked": 1,
  191. "id_elems": [
  192. {
  193. "PS": "1",
  194. "OS": "1",
  195. "LS": "2",
  196. "name": "USAGE_INSTRUCTIONS",
  197. "IS": "4",
  198. "id": "CE-USAGE_INSTRUCTIONS-4_2_1_1"
  199. }
  200. ],
  201. "mapCordinates": [
  202. {
  203. "top": 215.9384765625,
  204. "left": -639.0234375,
  205. "width": 29.1552734375,
  206. "height": 55.2314453125
  207. }
  208. ],
  209. "duplicate": 0,
  210. "content": "위로 당기며 입혀줍니다",
  211. "txtframe_name": "ceptxtCE-USAGE_INSTRUCTIONS-4_2_1_1-3"
  212. }
  213. ]
  214. }
  215. ]
  216. Supposed to be wanted like this by removing "txtFrameArr"
  217. I need to remove {"txtFrameArr"} but the key,value needs to be retain
  218. Is there any specific function in Java Spring for this solution?

应该是通过删除“txtframearr”来实现的

  1. Is there any specific function in Java Spring for this solution?
enxuqcxy

enxuqcxy1#

如果我正确理解你的意思-你可以使用json路径:
获取对象txtframearr键的所有值。
使用提取的值创建新的json数组:
第一步-你可以使用com.jayway。jsonpath:json-path:*,对于第二步-gson或jackson

  1. <dependency>
  2. <groupId>com.jayway.jsonpath</groupId>
  3. <artifactId>json-path</artifactId>
  4. <version>2.5.0</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.google.code.gson</groupId>
  8. <artifactId>gson</artifactId>
  9. <version>2.8.6</version>
  10. </dependency>

代码如下所示:

  1. List<Map<String, Object>> frames = JsonPath.parse(json).read("$[*].txtFrameArr");
  2. String newJson = new Gson().toJson(frames);
  3. System.out.println("object: " + newJson);
展开查看全部

相关问题