?
Solved

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

Posted on 2016-08-02
10
Medium Priority
?
62 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

766 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