There Are Two Activities, Activity A & Activity B
I Made an API Call in activity A And converted the JsonObject into string for my further Use now I need to Send That JsonObject To Activity B and I Used Intent.putExtra for that so for sending I converted it to String while sending, Now I Need to Again Convert it to JsonObject for a post request but I'm Unable to do So.
Or You Can Tell me an easy way to send the JsonObject As it is to Activity B Without Converting it to String.
Here is the sample of JsonObject
{
"data": {
"care_of": "S/O: Kaleen Bhaiya",
"full_name": "Munna Bhaiya",
"aadhaar_number": "123456789011",
"zip": "110088",
"gender": "M",
"share_code": "6921",
"face_score": -1,
"raw_xml": "https://link-to-docs",
"has_image": true,
"address": {
"loc": "Lehna Singh Market",
"street": "",
"house": "Flat No - 123",
"po": "Mirzapur",
"country": "India",
"subdist": "Mirzapur",
"vtc": "Mirzapur",
"dist": "North Mirzapur",
"state": "Uttar Pradesh"
},
"client_id": "aadhaar_v2_JlgixCkkkqinfMqtnThX",
"zip_data": "https://link-to-zip",
"profile_image": "base_64_image",
"face_status": false,
"dob": "1996-01-01"
},
"success": true,
"message_code": "success",
"status_code": 200,
"message": null
}
Your Help Is Much Appreciated
CodePudding user response:
JSON.parse(yourJSONString);
You can use JSON.parse() method for string to object co
CodePudding user response:
I'd recommend using gson library (by Google) for Serialization/Deserialization . You can find a nice guide here.
Assuming your POJO called Data
, it's going to be something like this:
Serialization - Convert object to json string
Data data = <your_object>;
Gson gson = new Gson();
String jsonString = gson.toJson(data);
Desirialization - convert json string to object
String dataJsonString = "<your_object_json_string>";
Gson gson = new Gson();
Data data = gson.fromJson(dataJsonString, Data.class);