Fetch nested data from Internet - flutter

How to fetch nested json response ? I can fetch direct value but cant fetch nested values
{
"username":"aa",
"data":{
"key":"value",
"anotherKey":"anotherValue"
}
}

You have to first decode your json like this-
var respBody = jsonDecode(response.body);
Then you can use respBody["data"]["key"]

Related

How to post a data using dio to an array wrapped inside a json and inside that array is also a json

How to post a data using dio to an array wrapped inside a json and inside that array is also a json. the structure of response is like below :
{
"result":[
{
"title":"String",
"caption":"String"
"related":[
{
"relatedTitle":"String",
"relatedCaption":"String"
}
]
}
]
}
I want to post value to the relatedTitle and relatedCaption inside the related key.
Please help out in it.
try to encode your json like:
var body = {
"title":"String",
"caption":"String",
"related":[
{
"relatedTitle":"String",
"relatedCaption":"String"
}
]
};
var response = await dio.post(Url, data: jsonEncode(body),);

React using axios await to fecth jsondata and store it in a variable

The data I am retrieving is in JSON format. Would like to store it in a JSON format in some class variable as well. As I want to send the json data to another component.
// Simple GET request using axios
axios.get(userDataURL)
.then((response) => {
// console.log(response.data);
jsondata =response.data.json;
console.log("2"+jsondata);
this.setState({ users: response.data.results })
} );
}```

get all data from mogoDB database instead of a single collection

i have two collections in my DB
const FastFood = mongoose.model("fast-food", foodSchema)
const Liquid = mongoose.model("liquid", foodSchema)
both of them have whole bunch of data inside. i want to get a data like:
{
fast-food: {
//data here
},
liquid: {
// data here
}
}
await FastFood.find({})this code returns only data in fast-food but i want all.i dont want to write one by one like
await FastFood.find({})
await Liquid.find({})
and so on.
is there any way of achieving this. smth like myDB.getallData() which return all data inside. Thank You!
Using mongoose by the way

Ionic and AngularFire2: How to retrieve data from a FireStore document?

I am probably missing some basics, hopefully this question is not too dumb...
I am trying to retrieve data from a document stored in FireStore. I am following the example provided here:
https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md
What I am wondering: After having access to the document:
this.itemDoc = afs.doc<Item>('items/1');
this.item = this.itemDoc.valueChanges();
How can I retrieve data from that document? I don't want . to use it in my html, but get the data from some fields and do something with it in TypeScript.
Obviously this.item is not an array so item[0].fieldname doesn't work...
TIA.
this.item is an observable, you need to subscribe to get the data.
this.itemDoc = afs.doc<Item>('items/1');
this.item = this.itemDoc.valueChanges();
this.item.subscribe(res=>{
console.log(res.fieldname);
}
//I assume you know how to use firebase with angular and ionic
import { AngularFirestore } from 'angularfire2/firestore';
constructor(private firestore:AngularFirestore)
{
}
readNote(){
this.readUsingObservable().subscribe(data => {
console.log(data[0].textnote); //0 means accessing first object
console.log(data[0].day);
//textnote and day are fields in collection object
})
}
readUsingObservable():Observable<any>{
return this.firestore.collection('yourcollectionname').valueChanges();
}

How to access BSON data "cells" in Meteor?

I have a problem:
In Meteor, I would like to be able to first fetch data from mongodb and then be able to update/edit the fetched data before returning it to the template.
So for example I have movies in the database in the following format:
{ name: "...", released: "..." }
In the code i would do something like this:
var movie = Movies.findOne({name: "Inception"});
Then I would like to get and edit the "release" data from the movie -variable. How to do it?
Use a transform:
return Movies.find({}, {transform:function(movie) {
if(movie.release) movie.release = movie.release + " _ This has been appended to release".
return movie;
});