0

my Scenario: passing the JSON data to function app to do some business functions like converting the input JSON to the correct format, for this i have used foreach loops and creating a json string.

the abopve scenario worked as expecting in local VS2017, but after publishing and while calling from logic apps it throws error.

to check manually i copied entire code into function app(Azure portal) and checked there when i called the function app, it shown some errors related to my JSON.

  1. Accessed JObject values with invalid key value: 0. Object property name expected.at data[0].columns.Count

then i have added another foreach on top of the other foreach and tried to take count as totalData["columns"].Count

  1. Cannot access child value on Newtonsoft.Json.Linq.JProperty. (when i place data[0].columns.Count to totalData["columns"].Count)

can you please help me how can the function app gives output same as VS2017 output. or working with json in function app.

enter image description here

Tân
  • 1
  • 15
  • 56
  • 102

1 Answers1

0

Cause you said you get the error in the portal and you post the code you local function. So I write a simple code to read the json data from request. And you don't mention your json schema, so the below is my test json data and the CSX code.

[
    {"columns":{
    "count":1
},
"rows":[1,2]},
{"columns":{
    "count":2
},
"rows":[3,4]}]

function.csx:

using System.Net;

public static async Task Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // Get request body
        dynamic data = await req.Content.ReadAsAsync<object>();

    int count = data[1].columns.count;
    int row = data[1].rows[0];

    log.Info("colums: "+count.ToString()+" row:"+row);
}

And here is the result pic:

enter image description here

If this json data is not what you want or you still have other questions, please feel free to let me know or provide more details.

George Chen
  • 13,703
  • 2
  • 11
  • 26