JSON 命名问题

本文关键字:问题 JSON | 更新日期: 2023-09-27 18:35:02

我是JSON和API的新手我正在尝试从我有 Json 的 API 中获取一些数据,并希望为它创建一个类.当我使用 josn2csharp 转换它时,我得到以下代码。请让我知道我的类的正确格式是什么,以便它转换为 json。

public class DataSet {
    public string __invalid_name__-i:nil { get; set; } }
public class GenericObject {
    public string __invalid_name__-xmlns:d2p1 { get; set; }
    public string __invalid_name__-i:type { get; set; }
    public string __invalid_name__#text { get; set; } }
public class Message {
    public string __invalid_name__-i:nil { get; set; } }
public class FunctionResponse {
    public string __invalid_name__-xmlns:i { get; set; }
    public string __invalid_name__-xmlns { get; set; }
    public DataSet DataSet { get; set; }
    public GenericObject GenericObject { get; set; }
    public Message Message { get; set; }
    public string Success { get; set; } }
public class RootObject {
    public FunctionResponse FunctionResponse { get; set; } }

用这个问题作为参考,我开始知道如何写

公共字符串 invalid_name #text { get; set; }

但是其他人呢。请帮忙

编辑 1:

{
   "DataSet": {
      "@nil": "true"
   },
   "GenericObject": {
      "@type": "d2p1:boolean",
      "#text": "true"
   },
   "Message": {
      "@nil": "true"
   },
   "Success": "true"
}

JSON 命名问题

示例:

{
 "json": 
   {
   "#thekeyinsidejsonproperty": "value"
   }
}

你应该有

public class RootObject
{
    [JsonProperty("json")]
    public Json jsonobj;
}
 public class Json
{
    [JsonProperty("#thekeyinsidejsonproperty")]
    public string somepropertyname{ get; set; }
}

希望对您有所帮助! :)