Can I get JSONObject from Default value of Firebase Remote Config

Viewed 6442

I need to fetch JSONObject from default value of Remote config in Firebase. By FirebaseRemoteConfig.getString(), it gets converted to the String, but not in the JSONObject, saying

org.json.JSONException: Unterminated object at character xx

I am attaching default values of remote config below:

  <entry>
    <key>welcome_message</key>
    <value>{"version" :1,"type":"category","name":"CATEGORY"}
    </value>
  </entry>

I am now attaching my Java Code below:

  String welcomeMessage = mFirebaseRemoteConfig.getString(WELCOME_MESSAGE_KEY);

  JSONObject categoryListInJson = new JSONObject(welcomeMessage);

Thanks in advance for the answers.

3 Answers

There are multiple solutions for this problem

1. Use firebaseConfig.setDefaults(Map); for setting up the default configuration.

2. Use backslash () before Double Quotes(") in your String in .xml file.

3. Replace

classpath 'com.android.tools.build:gradle:3.0.1' with
classpath 'com.android.tools.build:gradle:2.3.3'
and 
google() with
maven { url 'https://maven.google.com' }

4. Add android.enableAapt2 = false in gradle.properties

Related