From b2b5bdf6f42597e582da96aa56707e1f68d3936e Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 10 五月 2022 11:41:44 +0800
Subject: [PATCH] 优化 费用
---
java110-generator/src/main/java/com/java110/code/translate.java | 69 ++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/java110-generator/src/main/java/com/java110/code/translate.java b/java110-generator/src/main/java/com/java110/code/translate.java
index c7120f3..9bf5b21 100644
--- a/java110-generator/src/main/java/com/java110/code/translate.java
+++ b/java110-generator/src/main/java/com/java110/code/translate.java
@@ -1,5 +1,14 @@
package com.java110.code;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.parser.Feature;
+import com.java110.utils.util.StringUtil;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.Set;
+
/**
* @ClassName translate
* @Description TODO
@@ -9,4 +18,64 @@
* add by wuxw 2022/4/21
**/
public class translate {
+
+ public static void main(String[] args) throws Exception {
+ String enJsonStr = getJsonStr("C:\\project\\vip\\0911\\MicroCommunity\\java110-generator\\src\\main\\java\\com\\java110\\code\\enJson.json");
+ String cnJsonStr = getJsonStr("C:\\project\\vip\\0911\\MicroCommunity\\java110-generator\\src\\main\\java\\com\\java110\\code\\cnJson.json");
+
+
+ JSONObject enJson = JSONObject.parseObject(enJsonStr, Feature.OrderedField);
+ JSONObject cnJson = JSONObject.parseObject(cnJsonStr, Feature.OrderedField);
+
+ for (String key : cnJson.keySet()) {
+ Object keyValue = cnJson.get(key);
+ if (keyValue instanceof JSONObject) {
+ JSONObject keyObj = cnJson.getJSONObject(key);
+ int keyIndex = 0;
+ for(String subKeyObj :keyObj.keySet()){
+ String value = getObjValue(enJson,key,keyIndex);
+ keyObj.put(subKeyObj,value);
+ keyIndex++;
+ }
+ }
+ }
+
+ System.out.println(cnJson.toJSONString());
+ }
+
+ public static String getObjValue(JSONObject enJson, String objKey, int keyIndex) {
+ JSONObject jsonObject = null;
+ if(StringUtil.isEmpty(objKey)){
+ jsonObject = enJson;
+ }else{
+ jsonObject = enJson.getJSONObject(objKey);
+ }
+ if(jsonObject == null){
+ return "";
+ }
+ int index = 0;
+ for (String key : jsonObject.keySet()) {
+ if (index == keyIndex) {
+ return jsonObject.getString(key);
+ }
+ index++;
+ }
+
+ return "";
+
+ }
+
+ public static String getJsonStr(String jsonStr) throws Exception {
+ File file = new File(jsonStr);
+ BufferedReader in = new BufferedReader(new FileReader(file));
+ String str;
+ String context = "";
+ while ((str = in.readLine()) != null) {
+ context += (str + "\n");
+ //doDealHtmlNode(str,fileName);
+ }
+ return context;
+ }
+
+
}
--
Gitblit v1.8.0