-5

I have some characters as-

{"user_id":"7178717","firstname":"John","lastname":"Daniel","email":"test@example.com"}

Please some one tell me how to first represent/store these characters as it is in Java program ie can I represent these characters in enum or some array or some type etc. I need to know the type to represent or store this stream of characters And how to break these in occurrence of coma ie ',' I want to write an application in Java 8edn

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3528086
  • 73
  • 1
  • 1
  • 4

3 Answers3

2

It looks like JSON, you can use for eg. json.org. If you want to parse it as string you can use split function with "," as parameter which makes you array of strings. eg. string.split(",")

Milkmaid
  • 1,659
  • 4
  • 26
  • 39
  • But split() of String act on String objects. And this whole sequence could not be stored in String class variable or String []. Breaking and splitting I know but first how to take this sequence in java prog ? this is 1st ques. – user3528086 Dec 05 '14 at 07:00
1

You may want to define a class which has these fields e.g.:

long user_id;
String firstname;
String lastname;
String email;

You can try using this library to parse your input.

gson

peter.petrov
  • 38,363
  • 16
  • 94
  • 159
0

Your question is duplicate with this . However , jsonschema2pojo is the easiest way to generate java class from json data.

Community
  • 1
  • 1
dogankadriye
  • 538
  • 3
  • 13