WebAPI - Posting zu Wörterbuch mit json

Ich habe eine web-api-Methode, die wie folgt aussieht:

[HttpPost]
[Route("messages")]
public IHttpActionResult Post(IEnumerable<Email> email)
{
    AddToQueue(email);
    return Ok("message added to queue");
}

Meine E-Klasse sieht wie folgt aus momentan:

public string Body { get; set; }
public string From { get; set; }
public string Template { get; set; }
public string To { get; set; }        
public string Type { get; set; }

Und ich werde Entsendung zu meinem Post Methode unter Verwendung von fiddler', wie dieser:

User-Agent: Fiddler
Host: localhost:3994
Content-Length: 215
Content-Type: application/json; charset=utf-8
[
{"Body":"body","From":"from","To":"to","Template":"template"},
{"Body":"body1","From":"from1","To":"to1","Template":"template1"},
{"Body":"body2","From":"from2","To":"to2","Template":"template2"}
]

Diese funktioniert einwandfrei. Ich möchte jedoch hinzufügen können, ein Wörterbuch, um meine E-Mail-Klasse, wird also wie folgt Aussehen:

public string Body { get; set; }
public string From { get; set; }
public string Template { get; set; }
public string To { get; set; }        
public string Type { get; set; }
public Dictionary<string, string> HandleBars { get; set; }

Und ich änderte meine Anfrage wie folgt Aussehen:

[{
   "Body": "body",
   "From": "from",
   "To": "to",
   "Template": "template",
   "HandleBars": [{
      "something": "value"
    }]
}, 
{
   "Body": "body1",
   "From": "from1",
   "To": "to1",
   "Template": "template1"
 }, 
 {
   "Body": "body2",
   "From": "from2",
   "To": "to2",
   "Template": "template2"
 }]

Jedoch, wenn die Post-Methode empfängt alle E-Mail Felder gefüllt sind, mit Ausnahme der LENKER Wörterbuch. Was muss ich tun, um es richtig? Ist mein json-strukturierte falsch?

  • Wäre es nicht (in der json-array) {"value":"something","key":"key1"} ? (je nachdem, wie Sie Ihre Gehäuse json könnte es Wert de-Schlüssel)
  • HandleBars ist ein <string, string> und du bist nur vorbei an einer string, so gut wie Sie sein sollte und der Inhalt von innen HandleBars Namen key und value
  • siehe, hier ist schon eine Antwort stackoverflow.com/questions/2494294/...
InformationsquelleAutor ygetarts | 2015-12-01
Schreibe einen Kommentar