Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 69
  • Last Modified:

how to store String(json formatted String) value to a list

I am getting the below val as a string from DB
I want to add this values to a list
contactname,and contactmobile as one object we need to insert in list.

input:
{"contactName":"Girish Prabhu","contactMobile":"9952670691"},{"contactName":"Gopal Prasad","contactMobile":"9123560000"}


Expected output:

groupContacts:
            [
                {
                    "contactName": "Girish Prabhu",
                    "contactMobile": "9952670691"
                },{
                    "contactName": "Gopal Prasad",
                    "contactMobile": "9123560000"
                }
            ]
0
srikotesh
Asked:
srikotesh
1 Solution
 
Ryan ChongCommented:
since it's a string, why not just add in the front end back like this?
String newstring =  "groupContacts: [" + yourInpuy + "]";

Open in new window

0
 
CEHJCommented:
If you're manipulating this data programatically, you should probably be using a bean
0
 
gurpsbassiCommented:
as CEHJ said, use a JSON library
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
srikoteshAuthor Commented:
Thanks Ryan chong,

Hi CEHJ,

how can i get this string value using json.

I have create bean
public class ContactInfo {
	private List<Contact> contacts;
}

public class Contact {
	private String contactName;
	private String contactNo;
}

Open in new window

0
 
gurpsbassiCommented:
Use Jackson to serialise it.
Add annotations for jsonroot and property annotations to getters.
0
 
gurpsbassiCommented:
Unbelievable. Your going to use string manipulation  instead?
0
 
srikoteshAuthor Commented:
I don't know about Jackson serialization. so I prefer to go with that approach only
0
 
gurpsbassiCommented:
That's a bad choice.
0
 
srikoteshAuthor Commented:
I don't know about Jackson serialization
and how to get the string val from it.
0
 
gurpsbassiCommented:
Read up about it if you want to do it right.
Jackson is not the only option . There's others such as gson.

Being a developer means you should seek the best solutions that will be easy to maintain in future. Dont take shortcuts just because you can't be bothered to put the effort in.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now