http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3730|回复: 3

[求助] 用json生成对象中的问题

[复制链接]
发表于 2018-12-7 13:30:32 | 显示全部楼层 |阅读模式
[size=1.4em]1、服务器端返回的json数据如下:
[C#] 纯文本查看 复制代码
{
    "total": "9",
    "data": [
        {
            "id": "22",
            "batchid": "9c90dfbe89cd1d610f99c3c0b39e7cb3",
            "batchwriteid": "18023001",
            "batchname": "141",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": "111",
            "batchCreated_at": "1538718307",
            "batchSignupSum": "0"
        },
        {
            "id": "23",
            "batchid": "ae2ba50130026351d4375e00f0071b49",
            "batchwriteid": "18023002",
            "batchname": "51",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": null,
            "batchCreated_at": "1538718395",
            "batchSignupSum": null
        },
        {
            "id": "24",
            "batchid": "6ec51e0841c36c14a3813773b166315f",
            "batchwriteid": "18023003",
            "batchname": "111",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": null,
            "batchCreated_at": "1538718787",
            "batchSignupSum": "0"
        },
        {
            "id": "25",
            "batchid": "a5d3012fd85ec592f3bc59e1fce121cb",
            "batchwriteid": "18023004",
            "batchname": "fff",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": null,
            "batchCreated_at": "1538718918",
            "batchSignupSum": null
        },
        {
            "id": "26",
            "batchid": "8d4c8fc59607e631703b87f18c8948a5",
            "batchwriteid": "18023005",
            "batchname": "44444",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": "444",
            "batchCreated_at": "1538718950",
            "batchSignupSum": "0"
        },
        {
            "id": "29",
            "batchid": "803f66aa5246ca208c9d71a25b70f95e",
            "batchwriteid": "18023008",
            "batchname": "fds",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": "fwdd545",
            "batchCreated_at": "1538719405",
            "batchSignupSum": "0"
        },
        {
            "id": "31",
            "batchid": "6f6c1bfe9c78ce74167b9b82fa629baf",
            "batchwriteid": "18023009",
            "batchname": "唉唉唉",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": "ffff",
            "batchCreated_at": "1539092906",
            "batchSignupSum": "0"
        },
        {
            "id": "32",
            "batchid": "2bca117b2d6cefb2dc579ec179d4b921",
            "batchwriteid": "18023010",
            "batchname": "gfhfgh",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": "ghjyu",
            "batchCreated_at": "1539095295",
            "batchSignupSum": "35"
        },
        {
            "id": "38",
            "batchid": "8a01dc7ad30cfb0dc0c472cba14de214",
            "batchwriteid": "18022002",
            "batchname": "测试1",
            "systemname": "鸡蛋系统",
            "projectname": "直补个人培训",
            "batchaddress": "测试详细地址3",
            "batchCreated_at": "1543590853",
            "batchSignupSum": "0"
        }
    ]
}

2、我用[size=1.4em]Json生成类在线生成工具生成了一个类如下:
[C#] 纯文本查看 复制代码
using System;  
  
namespace MorePush  
{  
  
    public class Datum  
    {  
        public string id { get; set; }  
        public string batchid { get; set; }  
        public string batchwriteid { get; set; }  
        public string batchname { get; set; }  
        public string systemname { get; set; }  
        public string projectname { get; set; }  
        public string batchaddress { get; set; }  
        public string batchCreated_at { get; set; }  
        public string batchSignupSum { get; set; }  
    }  
  
    public class ListViewInfo  
    {  
        public string total { get; set; }  
        public IList<Datum> data { get; set; }  
    }  
  
}  

3、我写了这样一段代码:
[C#] 纯文本查看 复制代码
List<ListViewInfo> jsonlist = (List<ListViewInfo>)HttpHelper.JsonToObject<List<ListViewInfo>>(resultJson.ToString());

但在测试过程中,发现jsonlist仍然为0,这是什么情况啊?是不是我的语句哪里写错了?
QQ截图20181207132651.jpg


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2018-12-7 14:56:05 | 显示全部楼层
你的Json是一个对象,而你写成了一个集合,能生成才怪呢
[C#] 纯文本查看 复制代码
         ListViewInfo jsonlist = (ListViewInfo)HttpHelper.JsonToObject<ListViewInfo>(sb.ToString());


应该是这样写
发表于 2018-12-7 15:02:16 | 显示全部楼层
[C#] 纯文本查看 复制代码
            var sb = "{";
            sb = sb + "    \"total\": \"9\",";
            sb = sb + "    \"data\": [";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"22\",";
            sb = sb + "            \"batchid\": \"9c90dfbe89cd1d610f99c3c0b39e7cb3\",";
            sb = sb + "            \"batchwriteid\": \"18023001\",";
            sb = sb + "            \"batchname\": \"141\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": \"111\",";
            sb = sb + "            \"batchCreated_at\": \"1538718307\",";
            sb = sb + "            \"batchSignupSum\": \"0\"";
            sb = sb + "        },";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"23\",";
            sb = sb + "            \"batchid\": \"ae2ba50130026351d4375e00f0071b49\",";
            sb = sb + "            \"batchwriteid\": \"18023002\",";
            sb = sb + "            \"batchname\": \"51\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": null,";
            sb = sb + "            \"batchCreated_at\": \"1538718395\",";
            sb = sb + "            \"batchSignupSum\": null";
            sb = sb + "        },";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"24\",";
            sb = sb + "            \"batchid\": \"6ec51e0841c36c14a3813773b166315f\",";
            sb = sb + "            \"batchwriteid\": \"18023003\",";
            sb = sb + "            \"batchname\": \"111\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": null,";
            sb = sb + "            \"batchCreated_at\": \"1538718787\",";
            sb = sb + "            \"batchSignupSum\": \"0\"";
            sb = sb + "        },";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"25\",";
            sb = sb + "            \"batchid\": \"a5d3012fd85ec592f3bc59e1fce121cb\",";
            sb = sb + "            \"batchwriteid\": \"18023004\",";
            sb = sb + "            \"batchname\": \"fff\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": null,";
            sb = sb + "            \"batchCreated_at\": \"1538718918\",";
            sb = sb + "            \"batchSignupSum\": null";
            sb = sb + "        },";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"26\",";
            sb = sb + "            \"batchid\": \"8d4c8fc59607e631703b87f18c8948a5\",";
            sb = sb + "            \"batchwriteid\": \"18023005\",";
            sb = sb + "            \"batchname\": \"44444\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": \"444\",";
            sb = sb + "            \"batchCreated_at\": \"1538718950\",";
            sb = sb + "            \"batchSignupSum\": \"0\"";
            sb = sb + "        },";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"29\",";
            sb = sb + "            \"batchid\": \"803f66aa5246ca208c9d71a25b70f95e\",";
            sb = sb + "            \"batchwriteid\": \"18023008\",";
            sb = sb + "            \"batchname\": \"fds\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": \"fwdd545\",";
            sb = sb + "            \"batchCreated_at\": \"1538719405\",";
            sb = sb + "            \"batchSignupSum\": \"0\"";
            sb = sb + "        },";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"31\",";
            sb = sb + "            \"batchid\": \"6f6c1bfe9c78ce74167b9b82fa629baf\",";
            sb = sb + "            \"batchwriteid\": \"18023009\",";
            sb = sb + "            \"batchname\": \"唉唉唉\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": \"ffff\",";
            sb = sb + "            \"batchCreated_at\": \"1539092906\",";
            sb = sb + "            \"batchSignupSum\": \"0\"";
            sb = sb + "        },";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"32\",";
            sb = sb + "            \"batchid\": \"2bca117b2d6cefb2dc579ec179d4b921\",";
            sb = sb + "            \"batchwriteid\": \"18023010\",";
            sb = sb + "            \"batchname\": \"gfhfgh\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": \"ghjyu\",";
            sb = sb + "            \"batchCreated_at\": \"1539095295\",";
            sb = sb + "            \"batchSignupSum\": \"35\"";
            sb = sb + "        },";
            sb = sb + "        {";
            sb = sb + "            \"id\": \"38\",";
            sb = sb + "            \"batchid\": \"8a01dc7ad30cfb0dc0c472cba14de214\",";
            sb = sb + "            \"batchwriteid\": \"18022002\",";
            sb = sb + "            \"batchname\": \"测试1\",";
            sb = sb + "            \"systemname\": \"鸡蛋系统\",";
            sb = sb + "            \"projectname\": \"直补个人培训\",";
            sb = sb + "            \"batchaddress\": \"测试详细地址3\",";
            sb = sb + "            \"batchCreated_at\": \"1543590853\",";
            sb = sb + "            \"batchSignupSum\": \"0\"";
            sb = sb + "        }";
            sb = sb + "    ]";
            sb = sb + "}";

         ListViewInfo jsonlist = (ListViewInfo)HttpHelper.JsonToObject<ListViewInfo>(sb.ToString());
发表于 2018-12-7 15:04:18 | 显示全部楼层
嗯 是啊。你搞错对象了。
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-15 17:56

© 2014-2021

快速回复 返回顶部 返回列表