2

I am trying to read a json file and parse it using

jArray = JArray.Parse(json);

And filtering that array based on some conditions and returning same in ActionREsult OK

var categories = jArray.SelectTokens("[*]")
                   .Where(token => (string)token.SelectToken(jPath) == displayLevel);

            return Ok(categories);

But on client side I am receiving it as json string with empty array like this

[[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]],[[[]],[[]],[[]],[[]],[[]]]]

All this was working before.

Krunal Parmar
  • 491
  • 2
  • 19
  • 1
    Chances are you recently switched to asp.net-core 3.0 or 3.1. If so, you're using `System.Text.Json` instead of Json.NET. You need to switch back to Json.NET to use `JToken`. To do that, see [Where did IMvcBuilder AddJsonOptions go in .Net Core 3.0?](https://stackoverflow.com/q/55666826/3744182). – dbc Mar 31 '20 at 04:57
  • yeah we upgraded asp.net identity it got upgraded with that. Let me try doing that. – Krunal Parmar Mar 31 '20 at 05:05
  • Did that solve the problem? – dbc Apr 02 '20 at 18:08
  • @dbc yes thanks this helped. So now I explicitly serailize my jtoken when needed, using .net json serialization by default. – Krunal Parmar Apr 03 '20 at 08:55
  • I am having exact issue using aspnetcore 3.1. frustrated for days. – Steven Li Feb 17 '21 at 12:11

0 Answers0