Concat Same Name different Value JSON object into unique one

Ravi Patel

When I tried this:

JSONObject xyz = new JSONObject();
JSONArray abc = new JSONArray();


while(rs.next())  
{    

    String a = rs.getString("enrollno");
    String b = rs.getString("name");
    xyz.put("no" , a);
    xyz.put("name" ,b); 

    abc.put(xyz);
    System.out.println(abc.toString());
}  

outputs like:

[{"no":"IU121","name":"Heer"}]

[{"no":"IU12410500","name":"Ravi"},{"no":"IU12410500","name":"Ravi"}]

[{"no":"IU1241050050","name":"Rax"},{"no":"IU1241050050","name":"Rax"},{"no":"IU1241050050","name":"Rax"}]

But I want output like:

[{"no":"IU121","name":"Heer"},{"no":"IU12410500","name":"Ravi"},{"no":"IU1241050050","name":"Rax"}]
prasad

Try this

while(rs.next())  
{    

String a = rs.getString("enrollno");
String b = rs.getString("name");
JSONObject xyz = new JSONObject();
xyz.put("no" , a);
xyz.put("name" ,b); 

abc.put(xyz);
System.out.println(abc.toString());
} 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

concat different values into one column

From Java

JSON use multiple keys for the same value in an object

From Dev

How can I declare same object name for different class?

From Dev

Have one folder with files that have the same name but different file

From Dev

Copying attribute between different models' object but with the same attributes name

From Dev

Get different JSON representations of the same object

From Dev

Python pickle not one-to-one: different pickles give same object

From Dev

Summarize array of objects and calculate average value for each unique object name

From Dev

Concat JSON object into array

From Dev

SCSS variables - same name, different value in different media breakpoints

From Dev

Get one object with each unique property-value

From Dev

Disable sibling element when one is select where select name are same but value is different

From Dev

replace value if key is same in json object

From Dev

One interface with two methods having same name but different signature

From Dev

Json Deserialization with same property name with different case

From Dev

Hibernate: generate different (unique) IDs for same object reference in a list

From Dev

How to determine if an object is the same one or different

From Dev

Filtering column value based on unique value, but not repeated for different value of the same column on the same unique value

From Dev

Rename files in different directories with the same name, so each has a unique (numbered) name

From Dev

SQL concat rows with same name value

From Dev

Deserialize Xml Using Same Object With Different Element Name

From Dev

Recursive JSON object display with different child name

From Dev

Same object in one case, different object in another?

From Dev

How to generate unique name for each JSON value

From Dev

Move files with same name in different folders to one folder

From Dev

Concat Name and value in mongodb

From Dev

Merge 3 different json arrays in one object

From Dev

Converting one of the value of json to object

From Dev

how to store in one cell rows value what have the same name but different id?

Related Related

  1. 1

    concat different values into one column

  2. 2

    JSON use multiple keys for the same value in an object

  3. 3

    How can I declare same object name for different class?

  4. 4

    Have one folder with files that have the same name but different file

  5. 5

    Copying attribute between different models' object but with the same attributes name

  6. 6

    Get different JSON representations of the same object

  7. 7

    Python pickle not one-to-one: different pickles give same object

  8. 8

    Summarize array of objects and calculate average value for each unique object name

  9. 9

    Concat JSON object into array

  10. 10

    SCSS variables - same name, different value in different media breakpoints

  11. 11

    Get one object with each unique property-value

  12. 12

    Disable sibling element when one is select where select name are same but value is different

  13. 13

    replace value if key is same in json object

  14. 14

    One interface with two methods having same name but different signature

  15. 15

    Json Deserialization with same property name with different case

  16. 16

    Hibernate: generate different (unique) IDs for same object reference in a list

  17. 17

    How to determine if an object is the same one or different

  18. 18

    Filtering column value based on unique value, but not repeated for different value of the same column on the same unique value

  19. 19

    Rename files in different directories with the same name, so each has a unique (numbered) name

  20. 20

    SQL concat rows with same name value

  21. 21

    Deserialize Xml Using Same Object With Different Element Name

  22. 22

    Recursive JSON object display with different child name

  23. 23

    Same object in one case, different object in another?

  24. 24

    How to generate unique name for each JSON value

  25. 25

    Move files with same name in different folders to one folder

  26. 26

    Concat Name and value in mongodb

  27. 27

    Merge 3 different json arrays in one object

  28. 28

    Converting one of the value of json to object

  29. 29

    how to store in one cell rows value what have the same name but different id?

HotTag

Archive