1

To print the neccesary details we used the following command System.out.println(msgFromServer.data);

Now the following details are fetched from server

[{id={name=XDA Studio, color=red}, angle=-0.24456912236854822, piecePosition={pieceIndex=39.0, inPieceDistance=35.797426838065036, lane={startLaneIndex=1.0, endLaneIndex=1.0}, lap=2.0}}]

How to store these above server messages in json array variable and print value of angle alone.

2
  • 1
    Did you just put the output of three System.out.println() command? or one command gave you three lists? Commented Apr 26, 2014 at 11:57
  • sorry one command gives only one message Commented Apr 26, 2014 at 12:11

1 Answer 1

1

msgFromServer.data seems to return a List. Your List is something like

List<Map<String,Object>>

If you use Jackson parser, you could probably convert it to a Json String using the following code:

ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(list);

I have provided code for Jackson library, you could use any other with library specific implementation and code

Sign up to request clarification or add additional context in comments.

7 Comments

Well, in that case it is simple, just use one of the Json library to parse it to a Json string, like for example, I provided code for Jackson parser: jackson.codehaus.org i will also edit my answer then.. :)
can u provide little brief explanation with code example
Can you tell me what kind of object does msgFromServer.data returns?
public final Object data;
Can you cast this Object to a List? try it.. (List<Object>)msgFromServer.data
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.