I already checked the duplicate question and tried same code but doesn't work.
I have two json serialized objects and want to return those two outputs .
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Text;
public static async Task<HttpResponseMessage> Run(HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
var httpResult = data.a;
var sqlData = data.b;
var matchedList = new List<dynamic>();
var unmatchedList = new List<dynamic>();
foreach (var itemHttp in httpResult)
{
foreach (var itemSql in sqlData)
{
if (itemHttp.name == itemSql.tablename)
{
matchedList.Add(itemHttp);
}
else{
unmatchedList.Add(itemHttp.name);
}
}
}
var jsonToReturn1 = JsonConvert.SerializeObject(matchedList);
var jsonToReturn2 = JsonConvert.SerializeObject(unmatchedList);
return new HttpResponseMessage(HttpStatusCode.OK) {
Content = new StringContent( new { a= new{jsonToReturn1}, b= new {jsonToReturn2}}, Encoding.UTF8, "application/json")
};
}
input used for function -
{
"a": [
{
"id": "1",
"name": "aaa"
},
{
"id": "2",
"name": "bbb"
},
{
"id": "3",
"name": "ccc"
},
{
"id": "4",
"name": "ddd"
}
],
"b": [
{
"id": "111",
"tablename": "aaa"
},
{
"id": "222",
"tablename": "bbb"
}
]
}
aandb, which each have one property namedjsonToReturn1|2, whose value is a string containing the json you actually want. This doesn't sound like a correct outcome, but it "works" in that it returns JSON. Is that what happens; does something else happen; if you receive an error response, what is the error? Please specify exactly what you expected and what you saw instead.