Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – Convert JsonString to Json Object

Posted on November 11, 2022 By

Solution 1 :

JSON.parse(yourJSONString);

You can use JSON.parse() method for string to object co

Solution 2 :

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);

Solution 3 :

In our case,we do not need to convert json object to/from jsonString.
You can simply pass jsonObject to activity B from activity A as

intent.putExtra("jsonObject", YourJSonObject);

and recieve it on activity B as

YourJSonObject  yourjsonobject = (YourJSonObject)getIntent().getSerializableExtra("jsonObject");

Problem :

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

READ  [FIXED] Android Pie (9.0) - Writing a Shutdown or Restart Function - Application is Privileged
Powered by Inline Related Posts

Comments

Comment posted by Darkman

What json library are you using? builtin, gson, json.simple?

Comment posted by Rahul Pandey

@Darkman I’m using gson library

Comment posted by raw_hitt

Can you try JSONObject jsonObject = new JSONObject(myObj)

Comment posted by Rahul Pandey

Thanks you for your response, I Have already tried That but still doesn’t work !!

Comment posted by Rahul Pandey

Doesn’t work there is no method

Android Tags:android, java, json

Post navigation

Previous Post: [FIXED] android – How to detect when third party app’s dialog box appears in React native?
Next Post: [FIXED] android – Get the list of user SIM cards and select it – flutter

Related Posts

[FIXED] javascript – Custom draw navigation not rendering – React Native Android
[FIXED] java – What are the risks of using external libraries from unknown people ? Could it be malware? Android
[FIXED] javascript – Want to Print the text on the XPath Android
[FIXED] android – My Flutter app doesnt appear in the emulator when I try to run it Android
[FIXED] java – Room + RxJava 2 How to check for a record in a table in which a column is equal to a specific value Android
[FIXED] java – I am using recyclerview for loading images from Firebase Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme