0
votes

In Firebase Remote Config I have a valid json field named test:

{
    "title": "Hello, World!"
}

In the application I call jsonDecode(config.getString('test')) and it does not work because config.getString('test') spits out:

{title=Hello, World!}

I tried all possible methods on the config:

jsonDecode(config.getAll()['test'].asString());

and

jsonDecode(config.getValue('test').asString())

The app crashes since that is not valid JSON.

2
jsonDecode(config.getString('test'))["data"]["title"] - Hussnain Haidar
Nope, jsonDecode throws an exception because getString returns that strange Kotlin-like format - Denis Barzanov

2 Answers

1
votes

So the remote config value was fine, but in the app I had made wrong default value for test and it got fetched:

const defaultValue = {
    "title": "Hello, World!",
}
config.setDefaults({
    'test': defaultValue,
});

And it should have been:

config.setDefaults({
    'test': json.encode(defaultValue),
});

I thought it was Remote Config's fault

0
votes

Say this is your RemoteConfig map:

dummy
  {
    "foo": true,
    "bar": 100
  }

This is how you can retrieve the values:

var rawData = remoteConfig.getAll()['dummy'];
var map = jsonDecode(rawData?.asString() ?? yourDefaultValues);
bool foo = map['foo']; // true
int bar = map['bar']; // 100