首页新闻找找看学习计划

JSON里面包含多个JSON,我只能获取到"ret":0,"LastModifiedTime":"2015-10-12 11:47:11"这两个参数的值,但

0
[已解决问题] 解决于 2015-10-13 11:15

{"ret":0,"LastModifiedTime":"2015-10-12 11:47:11","BookInfoList":[{"BookID":22,"BookCover":"98c6e147-51bb-4ab5-8fb1-d4d299197d44.jpg","BookName":"人教新课标五年级下册","BookVersionName":"新课标人教版","GradeName":"五年级","TermName":"下学期","BookCatalogList":[{"CatalogID":1568,"CataLogName":"第一组","ChildCatalogs":[{"CatalogID":1569,"CataLogName":"草原","ChildCatalogs":[],"BookCourseList":[],"ParentCataLogID":1568},{"CatalogID":1570,"CataLogName":"丝绸之路","ChildCatalogs":[],"BookCourseList":[],"ParentCataLogID":1568},{"CatalogID":1571,"CataLogName":"白杨","ChildCatalogs":[],"BookCourseList":[],"ParentCataLogID":1568},{"CatalogID":1572,"CataLogName":"把铁路修到拉萨去","ChildCatalogs":[],"BookCourseList":[],"ParentCataLogID":1568},{"CatalogID":1573,"CataLogName":"词语盘点","ChildCatalogs":[],"BookCourseList":[{"CourseID":36741,"CourseName":"课时1","Courserecord":0,"EndTime":"","StartTme":"","LevelName":null,"SubjectName":null,"BookVersionName":null,"GradeName":null,"TermName":null,"CataLogName":null,"BookResourceList":[],"CourseNoteList":[]}],"ParentCataLogID":1568},{"CatalogID":1574,"CataLogName":"口语交际·习作一","ChildCatalogs":[],"BookCourseList":[],"ParentCataLogID":1568},{"

 

怎么获取JSON里面的“BookInfoList”和“BookCatalogList”数组的值呢?请教各位大神,谢谢!

梦随蝶舞的主页 梦随蝶舞 | 初学一级 | 园豆:195
提问于:2015-10-12 14:39
< >
分享
最佳答案
0

你都会得到ret的值了,后面的数组不会解析?

奖励园豆:5
稳稳的河 | 老鸟四级 |园豆:4183 | 2015-10-12 15:44

是的,因为“BookInfoList ”参数的参数类型是BookInfo ,我是在winform里面创建一个Model模型类,“BookInfoList ”里面的属性的类型应该写什么?

public int Ret { get; set; }
/// <summary>
/// 备课最新更新时间
/// </summary>
public string LastModifiedTime { get; set; }
/// <summary>
/// 教材信息
/// </summary>
public BookInfo BookInfoList { get; set; }
public int BookID { get; set; }
public string BookCover { get; set; }
public string BookName { get; set; }
public string BookVersionName { get; set; }
public string GradeName { get; set; }
public string TermName { get; set; }
/// <summary>
/// 教材目录(isbookcatalog为空或者false,BookCatalogList为null)
/// </summary>
public BookCatalog BookCatalogList { get; set; }
public int CatalogID { get; set; }
public string CataLogName { get; set; }

梦随蝶舞 | 园豆:195 (初学一级) | 2015-10-12 16:10

@梦随蝶舞: 你是前台返回到后台的json,前面2为都认为你是后台到前台的了,你直接可以用一个对象来转

public class A()
{
    public int Ret{get;set;}
    public string Time{get;set;}
    public List<BookInfo>   BookInfoList{get;set;}
}

public class BookInfo()
{
   public int BookID{get;set;}
   ...........
}
这样转
稳稳的河 | 园豆:4183 (老鸟四级) | 2015-10-12 16:18

@梦随蝶舞:说明你解析出来了,这个问题自己先找下原因

稳稳的河 | 园豆:4183 (老鸟四级) | 2015-10-12 17:25
其他回答(2)
0

什么叫“包含多个JSON”??

顾晓北 | 园豆:9530 (大侠五级) | 2015-10-12 14:42

专业术语说错了,怎么把这些数据转换过来呢?我只会获取"ret":0,"LastModifiedTime":"2015-10-12 11:47:11",这两个参数的值

支持(0) 反对(0) 梦随蝶舞 | 园豆:195 (初学一级) | 2015-10-12 15:10

大神,怎么获取"BookInfoList"和"BookCatalogList"里面的内容呢?

支持(0) 反对(0) 梦随蝶舞 | 园豆:195 (初学一级) | 2015-10-12 15:13

@梦随蝶舞: json都有了,直接eval呗,说说你的场景吧。。。

支持(0) 反对(0) 顾晓北 | 园豆:9530 (大侠五级) | 2015-10-12 15:19

@顾晓北: {"ret":0,"LastModifiedTime":"2015-10-12 11:47:11","BookInfoList":[{"BookID":22,"BookCover":"98c6e147-51bb-4ab5-8fb1-d4d299197d44.jpg","BookName":"人教新课标五年级下册","BookVersionName":"新课标人教版","GradeName":"五年级","TermName":"下学期","BookCatalogList":[{"CatalogID":1568,"CataLogName":"第一组","ChildCatalogs":[{"CatalogID":1569,"CataLogName":"草原","ChildCatalogs":[],"BookCourseList":[],"ParentCataLogID":1568},{"CatalogID":1570,"CataLogName":"丝绸之路","ChildCatalogs":[],"BookCourseList":[],

 

怎么获取"BookInfoList"里面的多个对象呢?我是在winform里面写的,创建了一个Model类,把需要返回参数封装了,然后另外一个类里面这样写的,可是数据获取不出来,麻烦帮我解决一下这个问题,谢谢!

public Model.GetDetailsResult GetDetails(string access_token, int userid, string tenant)
{
string url = string.Format(ServiceUrl.Lesson_GetDetails + "?access_token={0}&userid={1}&tenant={2}", access_token, userid, tenant);
HttpClient client = new HttpClient();
HttpResponseMessage getResponse = client.GetAsync(url).Result;
getResponse.EnsureSuccessStatusCode();
string result = getResponse.Content.ReadAsStringAsync().Result;
JavaScriptSerializer jss = new JavaScriptSerializer();
Model.GetDetailsResult gdr = jss.Deserialize<Model.GetDetailsResult>(result);
return gdr;
}

支持(0) 反对(0) 梦随蝶舞 | 园豆:195 (初学一级) | 2015-10-12 18:37

@梦随蝶舞: 你这不是代码都写出来了么?还需要什么?返回的数据已经反序列化出来了,你还需要什么东西?直接就可以访问啊。。。你的gdr数据结构是什么?

支持(0) 反对(0) 顾晓北 | 园豆:9530 (大侠五级) | 2015-10-13 08:32
0

問題沒問完?

objectName.BookInfoList[0].BookID

物件屬性用點

Array內容用[]

RosonJ | 园豆:2662 (老鸟四级) | 2015-10-12 14:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册