简体   繁体   English

使用Rest Sharp设计Rest API的嵌套类结构

[英]designing nested class structure for rest api using rest sharp

I am working with below mentioned structure where i have classes in that i have list of classes with a class name. 我正在使用下面提到的结构,其中有类,其中有类名称列表。 Each class has its mapping. 每个类都有其映射。

I need to query this using rest sharp from a rest service. 我需要使用来自rest服务的rest sharp来查询此内容。

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
  <Response status="Success">
  <Classes>
  <Class className="Library">
  <ClassMappings>   
  < ClassMapping key="cls1" /> 
  < ClassMapping key="cls2" /> 
  < ClassMapping key="cls3" /> 
  </ ClassMappings>
  </ Class>
  < Class className="Staff">
  </ Class>
    .
    .
    .
  </Classes>

I have designed this classes but its not giving me mappings properly. 我已经设计了此类,但是没有给我正确的映射。

public class Class
{
    public string className { get; set; }
    //public ClassMappings Mappings { get; set; }
    public List<ClassMapping> Mappings { get; set; }
}

public class Classes : List<Class> { }

//public class ClassMappings //: List<ClassMapping>
//{
//    public List<ClassMapping> ClassMapping { get; set; }
//}

public class ClassMapping
{
    public string key { get; set; }
}

You can see i have already tried the commented code also. 您可以看到我也已经尝试过注释代码。 Where class mappings is a different class. 其中类映射是不同的类。

Can anyone help me designing classes for rest call. 任何人都可以帮助我设计休息电话的课程。

Thanks 谢谢

The array should be named ClassMappings instead of Mappings . 该数组应命名为ClassMappings而不是Mappings

As a general solution you could load the xml as a generic object and then use the debugger to see the correct structure. 作为通用解决方案,您可以将xml作为通用对象加载,然后使用调试器查看正确的结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM