0

I am getting a response from a firebase function and dialogflow which hold some information that I need for further implementations. The response is a JSON, which I hold in mResultFromDialogFlow, which is a HashMap (String, Object) type variable.

I've searched other threads like this, but the strange thing was that my problem is at column 2, not 1 and I don't see the problem in the json. Here is the gson part. The error is thrown on the line with Properties!

Gson _gson = new Gson();
String _json = _gson.toJson(mResultFromDialogFlow.get("parameters"));
Properties data = _gson.fromJson(_json, Properties.class);
mTime = data.getProperty("date"); // String type variable
mDateFromUser = data.getProperty("time"); // String type variable

This is the response JSON:

{"date":"2019-07-19T12:00:00+03:00","time":"2019-07-19T14:00:00+03:00"}
5
  • Which Properties are you using? java.util.Properties? Commented Jul 18, 2019 at 13:15
  • So, apparantly, the _json has this value: "{\"time\":\"2019-07-19T14:00:00+03:00\",\"date\":\"2019-07-19T12:00:00+03:00\"}" @MC Emperor, yes Commented Jul 18, 2019 at 13:16
  • Have you added the quotes ? or is this the raw value ? Because the object should start with a { not a " Commented Jul 18, 2019 at 13:18
  • That looks like a JSON string converted to JSON. I suspect mResultFromDialogFlow.get("parameters") already returns a JSON string. With toJson(), you convert a JSON string to JSON. What happens if you try Properties data = _gson.fromJson(mResultFromDialogFlow.get("parameters"));? Commented Jul 18, 2019 at 13:19
  • @MCEmperor, you were right. I just needed to add mResultFromDialogFlow directly to _gson.fromJson Commented Jul 18, 2019 at 13:21

1 Answer 1

1

That looks like a JSON string converted to JSON. I suspect mResultFromDialogFlow.get("parameters") already returns a JSON string. With toJson(), you convert a JSON string to JSON.

If you try

Properties data = _gson.fromJson(mResultFromDialogFlow.get("parameters"), Properties.class);

it'll probably work.

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

4 Comments

Yes, this was it. I figured it out 1 minute earlier thanks to @MC Emperor
@DavidBuzatu Well, that's me
I am too tired, my bad. Thank you again
@DavidBuzatu You should get some sleep ;-)

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.