-1

I am trying to convert a complex map to Json String to pass to my Firebase Realtime Database.

The Map:

_data = {
  'name':{
          'description':'This is my description',
          'price': '700'
        },
  'name2':{...}
}

What I tried:

json.encode(_data)

This gives me an error:

Converting object to an encodable object failed
Ali Solanki
  • 640
  • 7
  • 16

2 Answers2

1

I got the mistake! I was also using a for loop for putting the data in the map. However while using json.encode(for loop) doesn't work somehow. I removed it and now it does.

Ali Solanki
  • 640
  • 7
  • 16
0
import 'dart:convert';

It's your map,

data = { 'name':{ 'description':'This is my description', 'price': '700' }, 'name2':{...} }

To convert like this,

Var jsonData=JsonEncoder().convert();
Shirsh Shukla
  • 5,491
  • 3
  • 31
  • 44