如何将 JavaScript 中的 base = { base: 'base', prop: '2093482938' } 数组获取到 C#?
How can I get this base = { base: 'base', prop: '2093482938' } array in JavaScript to C#?
base = { base: 'base', prop: '897070980989'}; ingr_mapArray.push(base); protien = { protein: 'protein', prop: '452341342453'}; ingr_mapArray.puh(protein);
我想在 C# 中获取 ingr_mapArray。并希望存储在 List<'Ingrediants> 中。我怎样才能得到这个数组?
这就是你应该做的事情
class Ingrediants
{
string Type { get; set; }
string Prop { get; set; }
}
然后在你需要的地方做你做的清单
List<Ingrediants> ingr_mapArray = new List<Ingrediants>();
Ingrediants base = new Ingrediants
{
Type = "base",
Prop = "897070980989"
};
ingr_mapArray.Add(base);
Ingrediants protien = new Ingrediants
{
Type = "protien",
Prop = "452341342453"
};
ingr_mapArray.Add(protien);
在您的示例中,base
对象有一个 属性 "base"
,类似地 protien
有 "protien"
,这不是您可以在同样class。所以我将其命名为 Type
,您可以在其中提供 base
或 protien
。
base = { base: 'base', prop: '897070980989'}; ingr_mapArray.push(base); protien = { protein: 'protein', prop: '452341342453'}; ingr_mapArray.puh(protein);
我想在 C# 中获取 ingr_mapArray。并希望存储在 List<'Ingrediants> 中。我怎样才能得到这个数组?
这就是你应该做的事情
class Ingrediants
{
string Type { get; set; }
string Prop { get; set; }
}
然后在你需要的地方做你做的清单
List<Ingrediants> ingr_mapArray = new List<Ingrediants>();
Ingrediants base = new Ingrediants
{
Type = "base",
Prop = "897070980989"
};
ingr_mapArray.Add(base);
Ingrediants protien = new Ingrediants
{
Type = "protien",
Prop = "452341342453"
};
ingr_mapArray.Add(protien);
在您的示例中,base
对象有一个 属性 "base"
,类似地 protien
有 "protien"
,这不是您可以在同样class。所以我将其命名为 Type
,您可以在其中提供 base
或 protien
。