How to parse class object to json and json to class object again using java?

0 votes

In my project I have two classes: TourManager and City. TourManager class has and array and a method called add.city() where I put the created cities. 

 TourManager tour = new TourManager();
 City city25 = new City("Maia", 100, 95);

 tour.addCity(city25); 

1) How can I parse the tour object with the cities added to jsonObject and send to custom code?

2) In my custom code, I also have a TourManager class, and I need receive the json request and parse the json object to TourManager again to do some processing. Is it possible to do that?

 

 

closed with the note: wrote in wrong place
asked Nov 1, 2017 in Android by Felipe Santos (10 points)
closed Nov 13, 2017 by Felipe Santos
Thanks for answer my question. Could you give me an example using a simple code on how to do it ? I couldn't understand how it work exactly.

1 Answer

0 votes

Hi Feilpe Santos,

Greetings from ShepHertz!!!!

Here are the way around to achieve your goal.

  • Creating JSON Request from class : You can create a method in your TourManager class that will create a Json from class members with respective keys if class contains array or array List you can use JSON Array for that.
  • Parsing Response From Json to class Object : Once you will receive response from custom code server, you can create another method in your TourManager that will generate class object with the help of your JSON response

Let  me know if it helps.

Thanks

Vishnu Garg

answered Nov 4, 2017 by Vishnu Garg (674 points)
Thanks for answer my question. Could you give me an example using a simple code on how to do it ? I couldn't understand how it work exactly
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...