-4

I need to create json string as per below using java: under ADDTNLINFO element how to add multiple elements as Tag .could any one help please ?

 {
       "ADDTNLINFO": 
        {
                "Tag": 
                  {
                    "name": "a",
                    "value": "10"
                  },
                "Tag": 
                  {
                    "name": "a b",
                    "value": "20"
                  },
                "Tag": 
                 {
                    "name": "a b c",
                    "value": "30"
                 }
         }
 }
mravu
  • 29
  • 1
  • 4
  • 1
    Well, I'd use a JSON library. I'm pretty sure there are *lots* of examples of generating JSON from Java. What research have you performed so far, and where are you stuck? – Jon Skeet Jan 22 '18 at 11:20

1 Answers1

0
import com.google.gson.Gson;
List<Dto> beans = service.something();
Gson gson = new Gson();
// convert your list to json
String jsonCartList = gson.toJson(beans);

You need to add Dependency for Google gson and it will according to your requirement

KuldeeP ChoudharY
  • 446
  • 1
  • 6
  • 22