Solved

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

Posted on 2016-08-02
10
52 Views
Last Modified: 2016-08-08
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
Comment
Question by:srikotesh
10 Comments
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41738769
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 41738828
If you're manipulating this data programatically, you should probably be using a bean
0
 
LVL 16

Expert Comment

by:gurpsbassi
ID: 41738952
as CEHJ said, use a JSON library
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Author Comment

by:srikotesh
ID: 41739539
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
 
LVL 16

Expert Comment

by:gurpsbassi
ID: 41739848
Use Jackson to serialise it.
Add annotations for jsonroot and property annotations to getters.
0
 
LVL 16

Expert Comment

by:gurpsbassi
ID: 41746549
Unbelievable. Your going to use string manipulation  instead?
0
 
LVL 2

Author Comment

by:srikotesh
ID: 41746675
I don't know about Jackson serialization. so I prefer to go with that approach only
0
 
LVL 16

Expert Comment

by:gurpsbassi
ID: 41747050
That's a bad choice.
0
 
LVL 2

Author Comment

by:srikotesh
ID: 41747055
I don't know about Jackson serialization
and how to get the string val from it.
0
 
LVL 16

Expert Comment

by:gurpsbassi
ID: 41747112
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question