static String Q2(String json1, String json2, String json3){ // Question:given th
ID: 3836423 • Letter: S
Question
static String Q2(String json1, String json2, String json3){
// Question:given three JSON Strings, combine them into a single JSON String
// The inputs are in the format:
// json1: {"number":9}
// json2: [10,14,0,12] <-- any number of ints
// json3: [{"key1":4},{"key2":5}] <-- always 2 objects
//
// and the output must be in the format:
// {"number":9,"array":[10,14,0,12],"key1":4,"key2":5}
//Tip: String totalString = " json1" " + json2 + ", " + json3 + ""; is not the way to do this
Can someone help me out with this java question?
Explanation / Answer
Please find my implementation.
static String Q2(String json1, String json2, String json3){
String res = "{";
res = res + json1.substring(1, json1.length()-1);
res = res + ", array: "+json2;
json3 = json3.substring(1, json3.length()-1);
String str[] = json3.split(",");
for(int i=0; i<str.length; i++){
res = res+"," + str[i].substring(1, str[i].length()-1);
}
res += "}";
return res;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.