如何在Web API中返回嵌套的TreeView JSON

时间:2018-05-07 10:50:36

标签: json asp.net-web-api

我是web API的新手。我需要一些帮助来生成JSON,如下所示。

 [
    {
        'id': 66,
        'text': 'This is the first comment.',
        'creator': {
            'id': 52,
            'display_name': 'Ben'
        },
        'respondsto': null,
        'created_at': '2014-08-14T13:19:59.751Z',
        'responses': [
            {
                'id': 71,
                'text': 'This is a response to the first comment.',
                'creator': {
                    'id': 14,
                    'display_name': 'Daniel',
                },
                'respondsto': 66,
                'created_at': '2014-08-14T13:27:13.915Z',
                'responses': [
                    {
                        'id': 87,
                        'text': 'This is a response to the response.',
                        'creator': {
                            'id': 52,
                            'display_name': 'Ben',
                        },
                        'respondsto': 71,
                        'created_at': '2014-08-14T13:27:38.046Z',
                        'responses': []
                    }
                ]
            }
        ]
    },
    {
        'id': 70,
        'text': 'Đây là bình luận thứ hai.',
        'creator': {
            'id': 12,
            'display_name': 'Nguyễn'
        },
        'respondsto': null,
        'created_at': '2014-08-14T13:25:47.933Z',
        'responses': []
    }
];

我的目的是为Image提供JSON数据。

我能够生成正常的JSON数据。我很惊讶如何在响应中创建响应,直到空响应出现。

任何帮助都将不胜感激。

更新:我找到了Answer

0 个答案:

没有答案