Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dont copy paste please provide full explanation static String Q2(String json1, S

ID: 3857566 • Letter: D

Question

Dont copy paste please provide full explanation

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

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;

   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote