0

I have following input JSON string which I want to convert to JSON Object.

{
  "myId": "SN001",
  "field2": "PM4334",
  "field3": "76.99",
  "field4": "2.0",
  "values": "0,1,2,3,4,5,6,7,8,9"
}

However I am getting following error while conversion using Gson library in my Java program.

com.google.gson.stream.MalformedJsonException: Expected ':' at line 1 column 150 path $.1

Requesting you to help me in this case.

Additional details

String inputMsg = inputMsgObj.toString();
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
DeviceMessage msg = gson.fromJson(inputMsg, DeviceMessage.class);

Getting the error message at third line while converting the message to DeviceMessage

Avinash
  • 1,363
  • 2
  • 15
  • 28
  • Please share the code. That would help to analyse. – Syed Dec 13 '19 at 14:37
  • Is values supposed to be a string or should it be an array of numbers? – mwarren Dec 13 '19 at 14:42
  • I believe your question [was answered here.](https://stackoverflow.com/questions/11484353/gson-throws-malformedjsonexception) – berkoab Dec 13 '19 at 14:47
  • I doubt the JSON you shared is the actual string you are parsing, as the one you provided is valid and the error says you are missing a colon (`:`). – Mr. Polywhirl Dec 16 '19 at 12:47
  • Hi Polywhir, The JSON is valid and if I remove other values in "values" element and keep only "0", it works. If I add the values like "0,1" then it gives me error. – Avinash Dec 16 '19 at 14:03
  • Hi mwarren, the expected input is the string from the source and that is comma separated. – Avinash Dec 16 '19 at 14:04
  • @berkoab, thanks for your suggestion. With this I am able to solve the problem. – Avinash Dec 16 '19 at 14:32
  • Yes. I was able to resolve the issue by following the details given in link – Avinash Dec 17 '19 at 07:19

0 Answers0