Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2016-08-02
10
Medium Priority
?
65 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

610 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