Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
颤振腹板&;Firebase—从JSON API接收的存储/日志信息_Firebase_Flutter_Dart_Flutter Web - Fatal编程技术网

颤振腹板&;Firebase—从JSON API接收的存储/日志信息

颤振腹板&;Firebase—从JSON API接收的存储/日志信息,firebase,flutter,dart,flutter-web,Firebase,Flutter,Dart,Flutter Web,我希望在访问者访问我的网站时,立即将从JSON API接收到的数据记录/存储到Firebase。没有用户帐户。API返回类似于-仅1个post的内容。我已经用一个函数实现了数据模型,但是我不知道如何解析(使用HTTP检索)JSON并将其存储在Firebase中。 以下是供参考的示例模型 导入“省道:转换”; 导入“包:http/http.dart”; 导入“包:website/user.dar”; 班岗{ int用户标识; int-id; 字符串标题; 弦体; Post({this.userId

我希望在访问者访问我的网站时,立即将从JSON API接收到的数据记录/存储到Firebase。没有用户帐户。API返回类似于-仅1个post的内容。我已经用一个函数实现了数据模型,但是我不知道如何解析(使用HTTP检索)JSON并将其存储在Firebase中。
以下是供参考的示例模型

导入“省道:转换”;
导入“包:http/http.dart”;
导入“包:website/user.dar”;
班岗{
int用户标识;
int-id;
字符串标题;
弦体;
Post({this.userId,this.id,this.title,this.body});
fromJson(映射json){
userId=json['userId'];
id=json['id'];
title=json['title'];
body=json['body'];
}
映射到JSON(){
最终地图数据=新地图();
数据['userId']=this.userId;
数据['id']=this.id;
数据['title']=this.title;
数据['body']=this.body;
返回数据;
}
}
类HTTP
我已经成功地设置了Firebase Analytics。目前未使用任何其他firebase软件包

更新:了解了如何在Dart中读取JSON。
导入'dart:convert';
导入“http:http.dart”;
类HttpService{
静态未来getLocation()异步{
响应=等待获取(
"http://jsonplaceholder.typicode.com/posts/1");
如果(response.statusCode==200){
final body=jsonDecode(response.body);
Post-Post=IPLocation.fromJson(body);
回程站;
}否则{
抛出异常(“加载Post.StatusCode:${response.StatusCode}失败”);
}
}
}

现在的问题仍然是-在Firebase中存储此信息的最佳方式是什么?我想将它们映射到每个访问者,但我无法设置用户帐户。

不确定这是否是您要寻找的,因为我从未使用过Firebase,但这是我用来从MySQL提取数据的

import 'dart:convert';

List<Listings> listingsFromJson(String str) =>
    List<Listings>.from(json.decode(str).map((x) => Listings.fromJson(x)));

String listingsToJson(List<Listings> data) =>
    json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class Listings{
  Listings({
    this.customerId,
    this.image,
    this.website,
  });

  String customerId;
  String image;
  String website;

  factory Listing.fromJson(Map<String, dynamic> json) => Listings(
        customerId: json["customer_id"],
        image: json["image"],
        website: json["website"],
      );

  Map<String, dynamic> toJson() => {
        "customer_id": customerId,
        "image": image,
        "website": website,
      };
}
导入'dart:convert';
列表listingsFromJson(字符串str)=>
List.from(json.decode(str.map)(x)=>Listings.fromJson(x));
字符串listingsToJson(列表数据)=>
encode(List.from(data.map((x)=>x.toJson());
课程表{
列表({
这是客户ID,
这个,这个形象,,
本网站,
});
字符串customerId;
字符串图像;
字符串网站;
工厂列表.fromJson(映射json)=>列表(
customerId:json[“客户id”],
image:json[“image”],
网站:json[“网站”],
);
映射到JSON()=>{
“客户id”:客户id,
“形象”:形象,
“网站”:网站,
};
}
Read Fetch和Read JSON输入。 这里是为了澄清

导入“省道:转换”;
导入“包:http/http.dart”;
导入“包:website/user.dar”;
班岗{
int用户标识;
int-id;
字符串标题;
弦体;
Post({this.userId,this.id,this.title,this.body});
fromJson(映射json){
userId=json['userId'];
id=json['id'];
title=json['title'];
body=json['body'];
}
映射到JSON(){
最终地图数据=新地图();
数据['userId']=this.userId;
数据['id']=this.id;
数据['title']=this.title;
数据['body']=this.body;
返回数据;
}
}
火基 请看使用FirebaseAuth设置匿名用户。然后设置并记录用户属性