Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.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
Android 无法将Json序列化为包含列表对象的对象(DART)_Android_Flutter_Serialization_Dart - Fatal编程技术网

Android 无法将Json序列化为包含列表对象的对象(DART)

Android 无法将Json序列化为包含列表对象的对象(DART),android,flutter,serialization,dart,Android,Flutter,Serialization,Dart,我在序列化时出错。控制台日志显示: > NoSuchMethodError: Class 'String' has no instance method 'forEach'. > Receiver: "no" Tried calling: forEach(Closure: (dynamic) => Null) dan > 0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) > 1

我在序列化时出错。控制台日志显示:

> NoSuchMethodError: Class 'String' has no instance method 'forEach'.
> Receiver: "no" Tried calling: forEach(Closure: (dynamic) => Null) dan
> 0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
> 1      new Article.fromJson (package:tribun_travel/model/article.dart:84:19)
> 2      new ResponseRead.fromJson (package:tribun_travel/model/response_read.dart:16:39)
> 3      BlogRepository.readNewsById (package:tribun_travel/repositories/blog_repository.dart:21:25)
> <asynchronous suspension>
> 4      BlogBloc.mapEventToState (package:tribun_travel/bloc/blog_bloc.dart:28:61) <asynchronous
> suspension>
我认为我的服务没有问题,因为它回报了我想要的。 但是,为什么序列化时仍有错误

更新 这是我的示例Json文件

{
    "status": "success",
    "message": "Found",
    "source": "memcached",
    "article": {
        "title": "Ini Alasan Pramugari Jarang Sakit Meski Terbang Berjam-jam",
        "fulltexts": "<p><</p>",
        "tag": [
            {
                "id": "1",
                "title": "a",
                "alias": "a"
            },
            {
                "id": "2",
                "title": "b",
                "alias": "b"
            }
        ],
        "related": [
            {
                "id": "79224",
            },
            {
                "id": "79219",
            }
        ]
    }
}
{
“状态”:“成功”,
“消息”:“已找到”,
“源”:“memcached”,
“第条”:{
“标题”:“这是一种美味的果酱”,

“全文”:“问题可能是您希望json中的
json['related']
json['tag']
是一个列表,但它实际上是一个字符串。检查实际的json文本,您可能会发现
“related”:“一些字符串”
,而不是
“related”:[]

请发布实际的JSON,以便我们可以找到


谢谢

post您的输入JSONi已经更新了问题HMMM,看起来还可以,
if(json['tag'!=null){
add
print(json['tag'])
if(json['related']!=null){
我已经把
print('apa itu-tag${json['tag]}打印出来了)
并且它打印了
flatter:apa itu TAG no
所以它不是你的JSON-add
print(JSON)
文章中。fromJson
请更新收到的JSON。。它可能有问题。在“相关”或“标记”中。
{
    "status": "success",
    "message": "Found",
    "source": "memcached",
    "article": {
        "title": "Ini Alasan Pramugari Jarang Sakit Meski Terbang Berjam-jam",
        "fulltexts": "<p><</p>",
        "tag": [
            {
                "id": "1",
                "title": "a",
                "alias": "a"
            },
            {
                "id": "2",
                "title": "b",
                "alias": "b"
            }
        ],
        "related": [
            {
                "id": "79224",
            },
            {
                "id": "79219",
            }
        ]
    }
}