1

I am receiving a string object in my spring controller class as follows

{'Gyr-x':10.11,'Gyr-y':9.66,'Gyr-z':10.93,'Temparature':30,'Pressure':101,'Humidity':15,'deviceId':1},{'Gyr-x':10.11,'Gyr-y':9.66,'Gyr-z':10.93,'Temparature':30,'Pressure':101,'Humidity':15,'deviceId':1}

Which is technically 2 arrays.

I want to convert this string object into JSON and do iteration on this two arrays, to fetch keys of each array. i do not wish to map this to any POJO classes as Jackson and Gson do.

2
  • They are not technically 2 arrays, they are two objects / dicts / maps. Please add some code and what you've already tried. Commented Jan 13, 2017 at 11:28
  • Btw. the input is not valid json: jsonformatter.curiousconcept.com Commented Jan 13, 2017 at 11:30

1 Answer 1

0

Use something like this: Parsing JSON string in Java

This only works, if your JSON is valid! So for your example, you have to split the string into two separate strings.

The you have something like a Map and you can iterate over the items like this: How to efficiently iterate over each Entry in a Map?

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

Comments

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.