Can't access Second Level of JSON String












-2















For a programming school project, I am making a weather app where I need to display the current temperature. In the JSON string the current temp is in the second level which I can't figure out how to access. In future I would also like to access the hourly and daily forecasts included in this string- if you have any ideas for how to do that. Any help would be appreciated. Here is my data:



{
"latitude":- 32.9283,
"longitude":151.7817,
"timezone":"Australia/Sydney",
"currently":{
"time":1546405401,
"summary":"Clear",
"icon":"clear-day",
"precipIntensity":0,
"precipProbability":0,
"temperature":93.03,
"apparentTemperature":93.03,
"dewPoint":58.07,
"humidity":0.31,
"pressure":1009.17,
"windSpeed":14.77,
"windGust":19.66,
"windBearing":68,
"cloudCover":0,
"uvIndex":7,
"visibility":7.75,
"ozone":276.4
},
"hourly":{
"summary":"Clear throughout the day.",
"icon":"clear-day",
"data":[
{
"time":1546405200,
"summary":"Clear",
"icon":"clear-day",
"precipIntensity":0,
"precipProbability":0,
"temperature":93.25,
"apparentTemperature":93.25,
"dewPoint":57.89,
"humidity":0.31,
"pressure":1009.18,
"windSpeed":14.78,
"windGust":19.53,
"windBearing":68,
"cloudCover":0,
"uvIndex":7,
"visibility":7.58,
"ozone":276.43
},
{
"time":1546408800,
"summary":"Clear",
"icon":"clear-day",
"precipIntensity":0,
"precipProbability":0,
"temperature":89.44,
"apparentTemperature":89.44,
"dewPoint":60.5,
"humidity":0.38,
"pressure":1008.99,
"windSpeed":14.58,
"windGust":21.84,
"windBearing":66,
"cloudCover":0,
"uvIndex":4,
"visibility":10,
"ozone":275.8
},
...


Here is my code:



Imports System.IO
Imports System.Net
Imports System.Drawing
Imports System.Web.Script.Serialization
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader

request = DirectCast(WebRequest.Create("https://api.darksky.net/forecast/412498ac9648999c8185723817a897d3/-32.9283,151.7817"), HttpWebRequest)
response = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New StreamReader(response.GetResponseStream())

Dim data As String
data = reader.ReadToEnd()

Dim jsonObject As JObject = JObject.Parse(data)
MessageBox.Show(jsonObject.SelectToken("currently").ToString)
Dim JsonArray As JArray = JArray.Parse(jsonObject.SelectToken("currently").ToString)
MessageBox.Show(jsonObject.SelectToken("temperature").ToString)


Error Message:




Newtonsoft.Json.JsonReaderException: 'Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.'











share|improve this question





























    -2















    For a programming school project, I am making a weather app where I need to display the current temperature. In the JSON string the current temp is in the second level which I can't figure out how to access. In future I would also like to access the hourly and daily forecasts included in this string- if you have any ideas for how to do that. Any help would be appreciated. Here is my data:



    {
    "latitude":- 32.9283,
    "longitude":151.7817,
    "timezone":"Australia/Sydney",
    "currently":{
    "time":1546405401,
    "summary":"Clear",
    "icon":"clear-day",
    "precipIntensity":0,
    "precipProbability":0,
    "temperature":93.03,
    "apparentTemperature":93.03,
    "dewPoint":58.07,
    "humidity":0.31,
    "pressure":1009.17,
    "windSpeed":14.77,
    "windGust":19.66,
    "windBearing":68,
    "cloudCover":0,
    "uvIndex":7,
    "visibility":7.75,
    "ozone":276.4
    },
    "hourly":{
    "summary":"Clear throughout the day.",
    "icon":"clear-day",
    "data":[
    {
    "time":1546405200,
    "summary":"Clear",
    "icon":"clear-day",
    "precipIntensity":0,
    "precipProbability":0,
    "temperature":93.25,
    "apparentTemperature":93.25,
    "dewPoint":57.89,
    "humidity":0.31,
    "pressure":1009.18,
    "windSpeed":14.78,
    "windGust":19.53,
    "windBearing":68,
    "cloudCover":0,
    "uvIndex":7,
    "visibility":7.58,
    "ozone":276.43
    },
    {
    "time":1546408800,
    "summary":"Clear",
    "icon":"clear-day",
    "precipIntensity":0,
    "precipProbability":0,
    "temperature":89.44,
    "apparentTemperature":89.44,
    "dewPoint":60.5,
    "humidity":0.38,
    "pressure":1008.99,
    "windSpeed":14.58,
    "windGust":21.84,
    "windBearing":66,
    "cloudCover":0,
    "uvIndex":4,
    "visibility":10,
    "ozone":275.8
    },
    ...


    Here is my code:



    Imports System.IO
    Imports System.Net
    Imports System.Drawing
    Imports System.Web.Script.Serialization
    Imports Newtonsoft.Json
    Imports Newtonsoft.Json.Linq
    Dim request As HttpWebRequest
    Dim response As HttpWebResponse = Nothing
    Dim reader As StreamReader

    request = DirectCast(WebRequest.Create("https://api.darksky.net/forecast/412498ac9648999c8185723817a897d3/-32.9283,151.7817"), HttpWebRequest)
    response = DirectCast(request.GetResponse(), HttpWebResponse)
    reader = New StreamReader(response.GetResponseStream())

    Dim data As String
    data = reader.ReadToEnd()

    Dim jsonObject As JObject = JObject.Parse(data)
    MessageBox.Show(jsonObject.SelectToken("currently").ToString)
    Dim JsonArray As JArray = JArray.Parse(jsonObject.SelectToken("currently").ToString)
    MessageBox.Show(jsonObject.SelectToken("temperature").ToString)


    Error Message:




    Newtonsoft.Json.JsonReaderException: 'Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.'











    share|improve this question



























      -2












      -2








      -2








      For a programming school project, I am making a weather app where I need to display the current temperature. In the JSON string the current temp is in the second level which I can't figure out how to access. In future I would also like to access the hourly and daily forecasts included in this string- if you have any ideas for how to do that. Any help would be appreciated. Here is my data:



      {
      "latitude":- 32.9283,
      "longitude":151.7817,
      "timezone":"Australia/Sydney",
      "currently":{
      "time":1546405401,
      "summary":"Clear",
      "icon":"clear-day",
      "precipIntensity":0,
      "precipProbability":0,
      "temperature":93.03,
      "apparentTemperature":93.03,
      "dewPoint":58.07,
      "humidity":0.31,
      "pressure":1009.17,
      "windSpeed":14.77,
      "windGust":19.66,
      "windBearing":68,
      "cloudCover":0,
      "uvIndex":7,
      "visibility":7.75,
      "ozone":276.4
      },
      "hourly":{
      "summary":"Clear throughout the day.",
      "icon":"clear-day",
      "data":[
      {
      "time":1546405200,
      "summary":"Clear",
      "icon":"clear-day",
      "precipIntensity":0,
      "precipProbability":0,
      "temperature":93.25,
      "apparentTemperature":93.25,
      "dewPoint":57.89,
      "humidity":0.31,
      "pressure":1009.18,
      "windSpeed":14.78,
      "windGust":19.53,
      "windBearing":68,
      "cloudCover":0,
      "uvIndex":7,
      "visibility":7.58,
      "ozone":276.43
      },
      {
      "time":1546408800,
      "summary":"Clear",
      "icon":"clear-day",
      "precipIntensity":0,
      "precipProbability":0,
      "temperature":89.44,
      "apparentTemperature":89.44,
      "dewPoint":60.5,
      "humidity":0.38,
      "pressure":1008.99,
      "windSpeed":14.58,
      "windGust":21.84,
      "windBearing":66,
      "cloudCover":0,
      "uvIndex":4,
      "visibility":10,
      "ozone":275.8
      },
      ...


      Here is my code:



      Imports System.IO
      Imports System.Net
      Imports System.Drawing
      Imports System.Web.Script.Serialization
      Imports Newtonsoft.Json
      Imports Newtonsoft.Json.Linq
      Dim request As HttpWebRequest
      Dim response As HttpWebResponse = Nothing
      Dim reader As StreamReader

      request = DirectCast(WebRequest.Create("https://api.darksky.net/forecast/412498ac9648999c8185723817a897d3/-32.9283,151.7817"), HttpWebRequest)
      response = DirectCast(request.GetResponse(), HttpWebResponse)
      reader = New StreamReader(response.GetResponseStream())

      Dim data As String
      data = reader.ReadToEnd()

      Dim jsonObject As JObject = JObject.Parse(data)
      MessageBox.Show(jsonObject.SelectToken("currently").ToString)
      Dim JsonArray As JArray = JArray.Parse(jsonObject.SelectToken("currently").ToString)
      MessageBox.Show(jsonObject.SelectToken("temperature").ToString)


      Error Message:




      Newtonsoft.Json.JsonReaderException: 'Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.'











      share|improve this question
















      For a programming school project, I am making a weather app where I need to display the current temperature. In the JSON string the current temp is in the second level which I can't figure out how to access. In future I would also like to access the hourly and daily forecasts included in this string- if you have any ideas for how to do that. Any help would be appreciated. Here is my data:



      {
      "latitude":- 32.9283,
      "longitude":151.7817,
      "timezone":"Australia/Sydney",
      "currently":{
      "time":1546405401,
      "summary":"Clear",
      "icon":"clear-day",
      "precipIntensity":0,
      "precipProbability":0,
      "temperature":93.03,
      "apparentTemperature":93.03,
      "dewPoint":58.07,
      "humidity":0.31,
      "pressure":1009.17,
      "windSpeed":14.77,
      "windGust":19.66,
      "windBearing":68,
      "cloudCover":0,
      "uvIndex":7,
      "visibility":7.75,
      "ozone":276.4
      },
      "hourly":{
      "summary":"Clear throughout the day.",
      "icon":"clear-day",
      "data":[
      {
      "time":1546405200,
      "summary":"Clear",
      "icon":"clear-day",
      "precipIntensity":0,
      "precipProbability":0,
      "temperature":93.25,
      "apparentTemperature":93.25,
      "dewPoint":57.89,
      "humidity":0.31,
      "pressure":1009.18,
      "windSpeed":14.78,
      "windGust":19.53,
      "windBearing":68,
      "cloudCover":0,
      "uvIndex":7,
      "visibility":7.58,
      "ozone":276.43
      },
      {
      "time":1546408800,
      "summary":"Clear",
      "icon":"clear-day",
      "precipIntensity":0,
      "precipProbability":0,
      "temperature":89.44,
      "apparentTemperature":89.44,
      "dewPoint":60.5,
      "humidity":0.38,
      "pressure":1008.99,
      "windSpeed":14.58,
      "windGust":21.84,
      "windBearing":66,
      "cloudCover":0,
      "uvIndex":4,
      "visibility":10,
      "ozone":275.8
      },
      ...


      Here is my code:



      Imports System.IO
      Imports System.Net
      Imports System.Drawing
      Imports System.Web.Script.Serialization
      Imports Newtonsoft.Json
      Imports Newtonsoft.Json.Linq
      Dim request As HttpWebRequest
      Dim response As HttpWebResponse = Nothing
      Dim reader As StreamReader

      request = DirectCast(WebRequest.Create("https://api.darksky.net/forecast/412498ac9648999c8185723817a897d3/-32.9283,151.7817"), HttpWebRequest)
      response = DirectCast(request.GetResponse(), HttpWebResponse)
      reader = New StreamReader(response.GetResponseStream())

      Dim data As String
      data = reader.ReadToEnd()

      Dim jsonObject As JObject = JObject.Parse(data)
      MessageBox.Show(jsonObject.SelectToken("currently").ToString)
      Dim JsonArray As JArray = JArray.Parse(jsonObject.SelectToken("currently").ToString)
      MessageBox.Show(jsonObject.SelectToken("temperature").ToString)


      Error Message:




      Newtonsoft.Json.JsonReaderException: 'Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.'








      arrays json vb.net parsing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 8:50









      QHarr

      35.8k82144




      35.8k82144










      asked Jan 2 at 7:11









      M. GreenM. Green

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Like the error says "currently" is not an array, it's an object. Arrays are denoted using square brackets whereas objects use curly braces {}.



          Try this instead:



          Dim currentlyObject As JObject = DirectCast(jsonObject("currently"), JObject)

          'Example usage.
          MessageBox.Show(currentlyObject("temperature"))





          share|improve this answer
























          • Massive help, Thanks very much.

            – M. Green
            Jan 3 at 0:53











          • @M.Green : Glad I could help! Good luck with your coding, and Welcome to Stack Overflow!

            – Visual Vincent
            Jan 3 at 1:10













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002557%2fcant-access-second-level-of-json-string%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Like the error says "currently" is not an array, it's an object. Arrays are denoted using square brackets whereas objects use curly braces {}.



          Try this instead:



          Dim currentlyObject As JObject = DirectCast(jsonObject("currently"), JObject)

          'Example usage.
          MessageBox.Show(currentlyObject("temperature"))





          share|improve this answer
























          • Massive help, Thanks very much.

            – M. Green
            Jan 3 at 0:53











          • @M.Green : Glad I could help! Good luck with your coding, and Welcome to Stack Overflow!

            – Visual Vincent
            Jan 3 at 1:10


















          0














          Like the error says "currently" is not an array, it's an object. Arrays are denoted using square brackets whereas objects use curly braces {}.



          Try this instead:



          Dim currentlyObject As JObject = DirectCast(jsonObject("currently"), JObject)

          'Example usage.
          MessageBox.Show(currentlyObject("temperature"))





          share|improve this answer
























          • Massive help, Thanks very much.

            – M. Green
            Jan 3 at 0:53











          • @M.Green : Glad I could help! Good luck with your coding, and Welcome to Stack Overflow!

            – Visual Vincent
            Jan 3 at 1:10
















          0












          0








          0







          Like the error says "currently" is not an array, it's an object. Arrays are denoted using square brackets whereas objects use curly braces {}.



          Try this instead:



          Dim currentlyObject As JObject = DirectCast(jsonObject("currently"), JObject)

          'Example usage.
          MessageBox.Show(currentlyObject("temperature"))





          share|improve this answer













          Like the error says "currently" is not an array, it's an object. Arrays are denoted using square brackets whereas objects use curly braces {}.



          Try this instead:



          Dim currentlyObject As JObject = DirectCast(jsonObject("currently"), JObject)

          'Example usage.
          MessageBox.Show(currentlyObject("temperature"))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 11:02









          Visual VincentVisual Vincent

          15.5k52052




          15.5k52052













          • Massive help, Thanks very much.

            – M. Green
            Jan 3 at 0:53











          • @M.Green : Glad I could help! Good luck with your coding, and Welcome to Stack Overflow!

            – Visual Vincent
            Jan 3 at 1:10





















          • Massive help, Thanks very much.

            – M. Green
            Jan 3 at 0:53











          • @M.Green : Glad I could help! Good luck with your coding, and Welcome to Stack Overflow!

            – Visual Vincent
            Jan 3 at 1:10



















          Massive help, Thanks very much.

          – M. Green
          Jan 3 at 0:53





          Massive help, Thanks very much.

          – M. Green
          Jan 3 at 0:53













          @M.Green : Glad I could help! Good luck with your coding, and Welcome to Stack Overflow!

          – Visual Vincent
          Jan 3 at 1:10







          @M.Green : Glad I could help! Good luck with your coding, and Welcome to Stack Overflow!

          – Visual Vincent
          Jan 3 at 1:10






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002557%2fcant-access-second-level-of-json-string%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          Npm cannot find a required file even through it is in the searched directory