Json的关键和价值

问题描述:

这就是我现在通过paypal在网站上建立会员的方式。Json的关键和价值

我想得一样,在这里完成:

"plan": { 
     "id": "P-rtfhfedh", 
     "state": "ACTIVE", 
     "name": "T-Shirt of the Month Club Plan", 
     "description": "Template creation.", 
     "type": "FIXED", 
     "payment_definitions": [ 
      { 
      "id": "PD-50606817NF8063316RWBZEUA", 
      "name": "Regular Payments", 
      "type": "REGULAR", 
      "frequency": "Month", 
      "amount": { 
       "currency": "USD", 
       "value": "100" 
      } 
      } 
     ] 

什么我能比现在做我的MVC的网站是这样的:

int orderid = Convert.ToInt32(HelperClass.Helper.Settings.NyTal(8)); 

     JsonPaypal jsonpaypal = new JsonPaypal(); 
     jsonpaypal.IdValue = id + orderid; 
     jsonpaypal.Name = "Medlemskab"; 
     jsonpaypal.description = "Medlemskab - Orderid: " + orderid; 
     jsonpaypal.start_date = DateTime.Now; 
     jsonpaypal.Plan = new string[] { 
      "id:" Convert.ToString(id + orderid), 
      "State": "ACTIVE", 

     }; 

类到JsonPaypal

public class JsonPaypal 
{ 
    public int IdValue 
    { 
     get; set; 
    } 

    public string Name 
    { 
     get; set; 
    } 

    public string description 
    { 
     get; set; 
    } 

    public DateTime start_date 
    { 
     get; set; 
    } 

    public string payerURL 
    { 
     get; set; 
    } 
    public string Plan 
    { 
     get; set; 
    } 

    public string URL 
    { 
     get; set; 
    } 

    public string Obj 
    { 
     get; set; 
    } 
} 

问题是,当我进入我的计划,并使多个对象,这也将显示从代码贝宝ma德。

错误在于如计划所述。

enter image description here

+0

“id:”Convert.ToString(id + orderid) - >“id”:Convert.ToString(id + orderid) –

+0

它给了我一个红色的错误并写入“Syntax error,'Expected”。当我关心并转化时,它就会成为现实。 @DmitriyZapevalov –

+0

这只是乍一看。乍一看:JsonPaypal.Plan是字符串,你正试图分配字符串'数组'。 ''''''初始化值也是用';'分开的,不能有':'。我建议您创建子类JsonPaypal.Plan并填写所有字段。 –

你需要设置你的public string Plan { get; set; }对象是一个string[]字符串数组。

像这样:public string[] Plan { get; set; }

这就是为什么你在波浪得到这个红色的,因为你的代码是试图建立一个正常的stringstring秒的阵列。

希望这会有所帮助!

EDIT此外,经过更多的观察,我意识到你正试图添加字符串到你的字符串数组不正确。

语法添加字符串是这样的:

string[] array = new string[] { "string 1", "string 2" }; 

在其中创建你的字符串,并使用其他属性/变量来创建它们,确保正确创建的字符串本身。关闭你的字符串并添加+来追加方法或属性的字符串。同样,要添加到方法或属性的字符串中,请添加+ " extra string stuff"

像这样

string[] array = new string[] { 
         "id: " + YourClass.Id, 
         "another string: " + myLocalVariable, 
         "yet another " + AClass.Property + " class" }; 

你的代码中设置jsonpaypal.Plan应该是...

jsonpaypal.Plan = new string[] { 
         "id: " + Convert.ToString(id + orderid), 
         "State: ACTIVE" }; 

希望这有助于!

+0

它没有帮助。 –

+0

我刚刚重新查看了您的代码并在上面编辑了我的答案。它会帮助,相信我。这也是以前的失败,因为你有错误的字符串来组成你的'string []'。看一看;我已经包含了一些例子。 –

+0

您的代码'{“id:”Convert.ToString(id + orderid),“State”:“ACTIVE”,}'是错误的。它必须这样写:'{“id:”+ Convert.ToString(id + orderid),“State:ACTIVE”};'正常工作。我已经将这段代码添加到了我的答案中。 –