Accessed JArray values with invalid key value: “fields”. Array position index expected

前端 未结 1 720
日久生厌
日久生厌 2020-12-11 03:52

I am using the guardian API to try and retrieve stories but keep receiving an exception. The string of json contains the below json, however I can\'t access the body using L

相关标签:
1条回答
  • 2020-12-11 04:26

    If you replace

    // This takes the current bitcoin price and formats it so there is the correct amount of decimal places
    string story = (string)ja["response"]["results"]["fields"]["body"];
    

    with

    // This takes the current bitcoin price and formats it so there is the correct amount of decimal places
    string story = (string)ja["response"]["results"][0]["fields"]["body"];
    

    that should work for your example. Note the square bracket after results in the example you provided, that indicates an array that should be accounted for in your access code.

    0 讨论(0)
提交回复
热议问题