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.

Yoga
  • 293
  • 3
  • 8
  • 23
  • They are not technically 2 arrays, they are two objects / dicts / maps. Please add some code and what you've already tried. – ppasler Jan 13 '17 at 11:28
  • Btw. the input is not valid json: https://jsonformatter.curiousconcept.com/ – ppasler Jan 13 '17 at 11:30

1 Answers1

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?

Community
  • 1
  • 1
ppasler
  • 3,579
  • 5
  • 31
  • 51