How i can access below object type value which is coming as request body from data factory output of another function app in http trigger function. Now i need to perform some operation with these ouput in http trigger function. { "functionName": "GoogleAuth", "method": "POST", "headers": {}, "body": { "Response": "[{"id":"hjk","name":"abc","description":"hki","brand":"Birds Eye","ean":"125","mediaStorageKey":"124","maxQuantity":6,"price":1.75,"size":224.0,"sizeUnits":"Grams"}]", "effectiveIntegrationRuntime": "DefaultIntegrationRuntime (West Europe)", "executionDuration": 0, "durationInQueue": { "integrationRuntimeQueue": 0 }, "billingReference": { "activityType": "ExternalActivity", "billableDuration": [ { "meterType": "AzureIR", "duration": 0.016666666666666666, "unit": "Hours" } ] } } }
I am trying to access it like this but is showing error.
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic body = JsonConvert.DeserializeObject(requestBody);
dynamic data = body["Response"];
product.OfferId = string.IsNullOrEmpty(Convert.ToString(data[0]["id"])) ? " " :Convert.ToString(data[0]["id"]);
Error:Cannot access child value on Newtonsoft.Json.Linq.JValue.
First, please set a break point to check the
requestBody
value, because the above value is not a valid json. You could search "Json Parse Online" and use online tools to verify it.After changing the response as below (remove the '"' before the '[' and after the ']'), your code works well
Second, from your comment, the dynamic data value is:
In this scenario, you can convert the
data
value to string, then, useJsonConvert.DeserializeObject()
convert the string value, after that, you could get the id value. code like this:The debug screenshot as below: