Link to home
Start Free TrialLog in
Avatar of srikotesh
srikotesh

asked on

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"
                }
            ]
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you're manipulating this data programatically, you should probably be using a bean
as CEHJ said, use a JSON library
Avatar of srikotesh
srikotesh

ASKER

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

Use Jackson to serialise it.
Add annotations for jsonroot and property annotations to getters.
Unbelievable. Your going to use string manipulation  instead?
I don't know about Jackson serialization. so I prefer to go with that approach only
That's a bad choice.
I don't know about Jackson serialization
and how to get the string val from it.
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.