Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java根据json字符串值将单个json对象分离为两个json对象?_Java_Android_Json - Fatal编程技术网

如何使用java根据json字符串值将单个json对象分离为两个json对象?

如何使用java根据json字符串值将单个json对象分离为两个json对象?,java,android,json,Java,Android,Json,我在这里提到了示例json对象 { "id": "1", "name": "sql", "age": 30, "car": "car", "office": "office", "cancel": "CANCEL", "ok": "OK" "cancel": "Anulo", "language": "en", "remove": "Remove", "ignore": "Ignore", "imag

我在这里提到了示例json对象

{
    "id": "1",
    "name": "sql",
    "age": 30,
    "car": "car",
    "office": "office",
    "cancel": "CANCEL",
    "ok": "OK"
    "cancel": "Anulo",
    "language": "en",
    "remove": "Remove",
    "ignore": "Ignore",
    "image_list": "Image List",
    "block": "Block",
    "loading": "Loading...",
    "splash_screen": "Splash Screen",
    "save": "Save",
    "skip": "Skip",
    "off": "Off",
    "vibration": "Vibration",
    "downloading": "Downloading...",
    "fix_it": "Fix it!"

}
与上面类似,我的JSON对象中的JSON对象有超过500个JSON字符串值。如何根据json字符串值将单个json对象拆分为两个json对象

第一个JSON对象

 {
    "id": "1",
    "age": 30,
    "office": "office"
    "cancel": "Anulo",
    "remove": "Remove",
    "image_list": "Image List",
    "loading": "Loading...",
    "save": "Save",
    "fix_it": "Fix it!"
    }
{ 
"name": "sql",
"car": "car",
"cancel": "CANCEL",
"ok": "OK"
"language": "en",
"ignore": "Ignore",
"block": "Block",
"splash_screen": "Splash Screen",
"skip": "Skip",
"off": "Off",
"vibration": "Vibration",
"downloading": "Downloading...",
}
第二个JSON对象

 {
    "id": "1",
    "age": 30,
    "office": "office"
    "cancel": "Anulo",
    "remove": "Remove",
    "image_list": "Image List",
    "loading": "Loading...",
    "save": "Save",
    "fix_it": "Fix it!"
    }
{ 
"name": "sql",
"car": "car",
"cancel": "CANCEL",
"ok": "OK"
"language": "en",
"ignore": "Ignore",
"block": "Block",
"splash_screen": "Splash Screen",
"skip": "Skip",
"off": "Off",
"vibration": "Vibration",
"downloading": "Downloading...",
}

我不知道这是好是坏

创建两个模型类

A类

package com.test;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class A {

@SerializedName("id")
@Expose
private String id;
@SerializedName("age")
@Expose
private Integer age;
@SerializedName("office")
@Expose
private String office;
@SerializedName("cancel")
@Expose
private String cancel;
@SerializedName("remove")
@Expose
private String remove;
@SerializedName("image_list")
@Expose
private String imageList;
@SerializedName("loading")
@Expose
private String loading;
@SerializedName("save")
@Expose
private String save;
@SerializedName("fix_it")
@Expose
private String fixIt;

//Getter Setter for all members...

}
B类

package com.test;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class B {

@SerializedName("name")
@Expose
private String name;
@SerializedName("car")
@Expose
private String car;
@SerializedName("cancel")
@Expose
private String cancel;
@SerializedName("ok")
@Expose
private String ok;
@SerializedName("language")
@Expose
private String language;
@SerializedName("ignore")
@Expose
private String ignore;
@SerializedName("block")
@Expose
private String block;
@SerializedName("splash_screen")
@Expose
private String splashScreen;
@SerializedName("skip")
@Expose
private String skip;
@SerializedName("off")
@Expose
private String off;
@SerializedName("vibration")
@Expose
private String vibration;
@SerializedName("downloading")
@Expose
private String downloading;

 //Getter Setter for all members...

}
现在使用GoogleGSON库来解析

Gson gson = new Gson();

String mainJson="put your main JSON here"

A a = gson.fromJson(json, A.class);
B b = gson.fromJson(json, B.class);    

它有模式吗?或者它只是一个随机对象?

这里有什么样的模式来分割json对象?解析第一个json,然后将它们添加到单独的json对象中,因为您似乎没有任何分割模式需要根据键值分割一些json字符串,该值与单个json混合@M.kazemakhgary由于没有确定的模式,可以根据长度将它们拆分为两个JSON对象,解析(JSON字符串)后将其作为JSON数组,它只是一个随机对象