Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Newtonsoft JSON反序列化和jsonfreeze_C#_Php_Json_Vb.net - Fatal编程技术网

C# Newtonsoft JSON反序列化和jsonfreeze

C# Newtonsoft JSON反序列化和jsonfreeze,c#,php,json,vb.net,C#,Php,Json,Vb.net,我有一个两个简单的PHP类 class Order{ public $orderNo; public $lines = array(); public $paid = false; public function addLine(OrderLine $line) { $this->lines[] = $line; } public function setPaid($paid = true) { $this->

我有一个两个简单的PHP类

class Order{
    public $orderNo;
    public $lines = array();
    public $paid = false;

    public function addLine(OrderLine $line) {
        $this->lines[] = $line;
    }

public function setPaid($paid = true) {
        $this->paid = true;
    }
}

class OrderLine{

public function __construct($item, $amount){
    $this->item = $item;
    $this->amount = $amount;
}

    public $item;
    public $amount;
    public $options;
}
序列化对象使用

输出:

{
  "#type": "Order",
  "orderNo": 123,
  "lines": [{
    "#type": "OrderLine",
    "item": "milk \"fuzz\"",
    "amount": 3,
    "options": null
  },{
    "#type": "OrderLine",
    "item": "cookies",
    "amount": 7,
    "options": {
      "#type": "#hash",
      "flavor": "chocolate",
      "weight": "1\/2 lb"
    }
  }],
  "paid": true
}
在VB.NET中发送字符串XMLRPC

使用Newtonsoft JSON获取活动对象


以及如何通过类比living VB.net或C#object的json字符串来创建兼容格式?

以下是您可以开始的内容。您可以创建一些具有表示JSON格式的属性的类(未经测试的代码,如idea所示):

公共类MyData
{
[JsonProperty(“#类型”)]
公共字符串类型{get;set;}
[JsonProperty(“#订单号”)]
公共int-OrderNo{get;set;
[JsonProperty(“已付”)]
公共bool付费{get;set;}
[JsonProperty(“行”)]
公共列表行{get;set;}
}
公共类MyDataLines
{
[JsonProperty(“#类型”)]
公共字符串类型{get;set;}
[JsonProperty(“期权”)]
公共MyDataLinesOptions选项{get;set;}
//……更多
}
公共类MyDataLinesOptions
{
//……更多
}
然后可以按如下方式序列化和反序列化数据:

string json = "the json data you received";
MyData myData = JsonConvert.DeserializeObject<MyData>(json);

// ...

json = JsonConvert.SerializeObject(myData);
string json=“您收到的json数据”;
MyData MyData=JsonConvert.DeserializeObject(json);
// ...
json=JsonConvert.SerializeObject(myData);
“键入”:“订单”

“#类型”:“订单行”


这不是一个属性,这是对象类型的指示

\uu
谢谢,它工作了,我意识到了它的本质!哦,对不起,我完全忽略了它是vb.net,但我很高兴它帮助你获得了实际的想法。欢迎使用StackOverflow;-)StackOverflow很棒的服务!对于服务器多年来,我发现了很多问题和解决方案。困难在于我不是英语高手。我不得不用翻译来解决一个非常重要的问题。再次感谢!
public class MyData
{
    [JsonProperty("#type")]
    public string Type { get; set; }

    [JsonProperty("#orderNo")]
    public int OrderNo { get; set; 

    [JsonProperty("paid")]
    public bool Paid { get; set; }

    [JsonProperty("lines")]
    public List<MyDataLine> Lines { get; set; }
}

public class MyDataLines
{
    [JsonProperty("#type")]
    public string Type { get; set; }

    [JsonProperty("options")]
    public MyDataLinesOptions Options { get; set; }

    // ... more
}

public class MyDataLinesOptions
{
    // ... more
}
string json = "the json data you received";
MyData myData = JsonConvert.DeserializeObject<MyData>(json);

// ...

json = JsonConvert.SerializeObject(myData);