Json的关键和价值 [英] Key and value in Json
问题描述
这就是我现在通过Paypal在网站上建立会员的方式.
This is how I work right now to build up membership on the website via paypal.
我想在这里完成这样的工作:
I would like to get done like that here:
"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网站中所做的就是这样:
What I have done than to now in my MVC site it is like this:
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的类
Class to 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;
}
}
问题是当我进入计划并制作多个对象时,该对象也会从创建的贝宝代码中显示出来.
The problem is when I go into my plan and make multiple object which will also be shown from the code paypal made.
故障是按计划所说的.
推荐答案
您需要将public string Plan { get; set; }
对象设置为string[]
字符串数组.
You need to set your public string Plan { get; set; }
object to be a string[]
string array.
像这样:public string[] Plan { get; set; }
这就是为什么您会花红的原因,因为您的代码试图将普通的string
设置为string
s的数组.
This is why you are getting this red squiggly, as your code is trying to set a normal string
to an array of string
s.
希望这会有所帮助!
编辑另外,经过更多查看,我意识到您正在尝试将字符串错误地添加到字符串数组中.
EDIT Also, after more looking, I realised you are trying to add strings to your string array incorrectly.
添加字符串的语法如下:
Syntax for adding strings is like this:
string[] array = new string[] { "string 1", "string 2" };
在创建字符串以及使用其他属性/变量创建字符串的位置,请确保正确创建了字符串本身.关闭您的字符串,并添加+
以追加方法或属性中的字符串.同样,要从方法或属性添加到字符串,请添加+ " extra string stuff"
.
Where you are creating your strings, and using other properties/variables to create them, ensure you are creating the string itself correctly. Close off your string and add +
to append strings from methods or properties. Likewise, to add to a string from a method or property, add + " extra string stuff"
.
赞
string[] array = new string[] {
"id: " + YourClass.Id,
"another string: " + myLocalVariable,
"yet another " + AClass.Property + " class" };
您应该在其中设置jsonpaypal.Plan
的代码...
Your code where setting jsonpaypal.Plan
should be...
jsonpaypal.Plan = new string[] {
"id: " + Convert.ToString(id + orderid),
"State: ACTIVE" };
希望这会有所帮助!
这篇关于Json的关键和价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!