2015-08-08 110 views
-1

我希望你能再次幫助我,我有一個包含對象容器的c#類,我需要從json對象中填充這個類對象。將JSON參數傳遞給Web API

public class user { public string name {get;set;} public userAttributes {get;set;}} 

public class userAttributes { int id {get; set;} string value {get;set;}} 

我使用谷歌的郵遞員使用URL編碼的選項傳遞參數,我不知道什麼是能夠得到this.i想過去的userAttribute這樣確切的JSON格式:

"userAttributes": [ 
{ 
    "Values": [ 
    { 
     "id": 1, 
     "Value": "sample string 2" 
    }, 
    { 
     "id": 1, 
     "Value": "sample string 2" 
    } 
    ] 
+0

'Serialize'類型爲'userAttributes'的對象,並且您擁有它。 –

回答

1

你可以試試這個,

public class UserAttribute 
{ 
    public string Id { get; set; } 
    public string Value { get; set; } 
}  
public class UserAttributes 
{ 
    public IList<UserAttribute> UserAttributes { get; set; } 
} 

的Json

{"UserAttributes": [{ "Id":"1" , "Value":"sample string 1" }, 
        { "Id":"2" , "Value":"sample string 2" }]}