0

Hi I have a question about reading a json using flutter

The code below returns in the string value -> {"return": 2}. But when I print the valuemap.values ​​I have the following result: (2).

How do I do it to read only the integer value? ,

Dart Code:

Future<int> login(String Email, String Password) async {
    //Ret rappresenta il valore di ritorno della funzione 
    var ret=0;
    Map map={
      'Username': Email,
      'Password':Password
    };
    String value=await apiRequest("/login", map);
    print("Valore prima del parse:" +value);
    Map valueMap = json.decode(value);
    print("Stampa di valore:" + valueMap.values.toString());
    return ret;
  }
1
  • Try that: print("Stampa di valore:" + valueMap['return'].toString()); Commented Jan 24, 2020 at 13:25

2 Answers 2

2

Try this,

...

Map valueMap = json.decode(value);
int returnValue = valueMap["return"];
print("Stampa di valore: $returnValue");
Sign up to request clarification or add additional context in comments.

Comments

1

If you are successful to get the string then you just access it valueMap["valuMap"] and assign to integer value

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.