0

I'm using JObject.Parse and it's not a valid json as it has two {{ in the beginning and two }} at the end instead of only one of each.

Tried catching exception but didn't hit the exception of my try catch. If I remove the extra { in the beginning and the extra } in the end jsonFormatter/validator webpage says it's okey.

  var URL = "https://api.instagram.com................my access token etc";
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri(URL);

  HttpResponseMessage response = client.GetAsync(URL).Result;

        using (HttpContent content = response.Content)
        {
            Task<string> result = content.ReadAsStringAsync();
            JObject json = JObject.Parse(result.Result);
        }

So reuslt.Result looks like this: "{\"pagination\": {}, \"data\": [{\"id\".........

and json starts looks like this: {{ "pagination": {}, "data": [ { "id": "20...............

When copying the json into formatter/validator and removing the extra { in the beginning and the extra } in the end everything is okey. So I expect the output json from JObject.Parse should look like this: { "pagination": {}, "data": [ { "id": "20...............

I can not understand why I'm getting these extra {} things?

dbc
  • 104,963
  • 20
  • 228
  • 340
JoBo
  • 235
  • 4
  • 17
  • You really need to start using `async` and `await` in this code, doing `.Result` on tasks can be very dangerous. – DavidG Aug 13 '19 at 13:27
  • Also, what makes you think you are getting these extra braces? `JObject` is not a string, it's a class. – DavidG Aug 13 '19 at 13:29
  • after parsing data, you can get data by json["pagination"]..... – Colonel Software Aug 13 '19 at 13:45
  • - I would love to use async and await, could you please tell me how David? I don't know why I'm getting the extra braces which is why I posted the question as I need help. – JoBo Aug 14 '19 at 06:52
  • The two `{{` and `}}` are artifacts of how Visual Studio and VSCode visualize a `JObject`. I have no idea why it does so but lots of people get confused by it. If you want to know what the `JObject` really looks like when formatted as JSON, in the Immediate Window, type `Console.WriteLine(json)` and its raw `ToString()` text will be displayed without any "helpful" escaping or visualization artifacts added by Visual Studio / VSCode. – dbc Dec 06 '22 at 20:44

0 Answers0