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":"9 952670691" },{"contac tName":"Go pal Prasad","contactMobile":"9 123560000" }
Expected output:
groupContacts:
[
{
"contactName": "Girish Prabhu",
"contactMobile": "9952670691"
},{
"contactName": "Gopal Prasad",
"contactMobile": "9123560000"
}
]
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":"9
Expected output:
groupContacts:
[
{
"contactName": "Girish Prabhu",
"contactMobile": "9952670691"
},{
"contactName": "Gopal Prasad",
"contactMobile": "9123560000"
}
]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're manipulating this data programatically, you should probably be using a bean
as CEHJ said, use a JSON library
ASKER
Thanks Ryan chong,
Hi CEHJ,
how can i get this string value using json.
I have create bean
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;
}
Use Jackson to serialise it.
Add annotations for jsonroot and property annotations to getters.
Add annotations for jsonroot and property annotations to getters.
Unbelievable. Your going to use string manipulation instead?
ASKER
I don't know about Jackson serialization. so I prefer to go with that approach only
That's a bad choice.
ASKER
I don't know about Jackson serialization
and how to get the string val from it.
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.
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.