我已经阅读了大量文档并阅读了相关帖子,但我仍然无法成功地为包含多个元素的Action数组构造Json。
第一个元素是包含自己的几个元素的“记住”操作。第二个action元素是一个"Collect“操作。
我可以添加第一个元素,但第二个元素无法添加。我发布的代码包含错误。我无法添加第二个"Collect“元素。我是接近了还是离得很远?任何指导都是非常感谢的。
[HttpPost]
[Route("AcceptTask")]
internal string BuildAcceptCall(UserData ud)
{
log.Debug("Entering BuildAcceptCall");
var j = new
{
actions = new[]
{
new
{
remember = new
{
ud.AccountId,
EngineId = ud.EngineId,
ResidentTelephone = ud.ResidentTelephone,
OutboundCallerId = ud.OutboundCallerId,
UnitNumber = ud.UnitNumber,
BuildingNumber = ud.BuildingNumber,
Pets = ud.Pets,
Alarm = ud.Alarm,
EmergencyId = ud.EmergencyId,
CallDate = ud.CallDate,
WorkOrder = ud.WorkOrder,
CurrentLocation = ud.CurrentLocation
}, //close remember element
collect = new
{
name = "DidTechAcceptCall",
questions = new[]
{
new
{
question = "This is a maintenance call from Spring Meadows. will you accept the call?",
name = "OffferCallToTech",
type="Twilio.YES_NO"
}
},
on_complete = new
{
redirect = new
{
uri = @"https://8.40.212.131/MedsDispatch/api/Dispatch/EntryPoint_AutoPilot",
method = "post"
}
}
}//close the collect element
} //close the new
}; //close the array
string theObject = Newtonsoft.Json.JsonConvert.SerializeObject(j); ;
return Newtonsoft.Json.JsonConvert.SerializeObject(j);
}发布于 2019-05-31 00:45:05
我强烈建议您执行以下一项或全部操作
Task控制台。不管怎样,下面是代码
var j = new { actions = new object[]{
new{
remember = new{
data = "data"
}
},
new{
collect = new{
name = "DidTechAcceptCall",
questions = new[]
{
new
{
question = "This is a maintenance call from Spring Meadows. will you accept the call?",
name = "OffferCallToTech",
type="Twilio.YES_NO"
}
},
on_complete = new
{
redirect = new
{
uri = @"https://8.40.212.131/MedsDispatch/api/Dispatch/EntryPoint_AutoPilot",
method = "post"
}
}
}
}
}
};
string theObject = Newtonsoft.Json.JsonConvert.SerializeObject(j);
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(j));这就产生了
{
"actions": [
{
"remember": {
"data": "data"
}
},
{
"collect": {
"name": "DidTechAcceptCall",
"questions": [
{
"question": "This is a maintenance call from Spring Meadows. will you accept the call?",
"name": "OffferCallToTech",
"type": "Twilio.YES_NO"
}
],
"on_complete": {
"redirect": {
"uri": "https://8.40.212.131/MedsDispatch/api/Dispatch/EntryPoint_AutoPilot",
"method": "post"
}
}
}
}
]
}https://stackoverflow.com/questions/56305379
复制相似问题