0
私はC#の辞書データ型の新機能です。私は、このモデルアイテムを得た:私はJSONオブジェクトに整数ではなく、言語の文字列を与えたい辞書からモデル項目への値の取得
[Route("{id}/settings")]
[HttpGet]
public async Task<HttpResponseMessage> GetProjectSettings(Guid id)
{
var projectSettings = new ProjectSettings
{
Id = id,
language = new Dictionary<int, string>() {
{1,"English"},
{2,"Spanish"}},
languageChoice = //get language by ID
};
if (projectSettings != null)
{
return Request.CreateResponse<ProjectSettings>(HttpStatusCode.OK, projectSettings);
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Project not found");
}
}
:
public Dictionary<int, string> language { get; set; }
public string languageChoice { get; set; }
はその後、私のコントローラで、私はこれを得ました。どうやってやるの?既存のDictionary<int, string>
その後、あなたはそれから新しいDictionary<int, int>
を作成することができますを変更したくない場合は
種類は
あなたは '{" 1 ":" English "}'を使いますか? –
たとえば、jsonオブジェクトでは、この言語のようにしたいと思っています。選択肢: "1"で、languageChoice: "English" – Fearcoder
[{{"languageChoice":1}、{"languageChoice":2}] ' –