0

I work with a web service that allows me to receive objects from my database. Now I try to send an object to my database through my web service. This object when I receive it is presented as an array of tables, now how to serialize it and send it and to the server with Json?

The json of the object that I receive and that I try to send to the server in turn

[[" IF THE CROWN FITS - PINCEAUX MAQUILLAGE",20000,20000," IF THE CROWN FITS - PINCEAUX MAQUILLAGE",null,"2"]
1
  • What do you want help for? You example are already JSON so it should work? Or do you want to parse the JSON into an object? But since we don't know what each field are, it is really not possible to help you with that. And without an example of your data class, we can't help you with how to convert your data into JSON. Commented Jul 23, 2020 at 14:47

1 Answer 1

1

Can you just

import 'dart:convert';

then as an example:

var scores = [
  {'score': 40},
  {'score': 80},
  {'score': 100, 'overtime': true, 'special_guest': null}
];

var jsonText = jsonEncode(scores);
assert(jsonText ==
    '[{"score":40},{"score":80},'
        '{"score":100,"overtime":true,'
        '"special_guest":null}]');

quote from the document:

Only objects of type int, double, String, bool, null, List, or Map (with string keys) are directly encodable into JSON. List and Map objects are encoded recursively.

And check this link https://dart.dev/guides/libraries/library-tour#dartconvert---decoding-and-encoding-json-utf-8-and-more for more details.

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

Comments

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.