Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am very new to this, but I am trying to write a Web API to get a JSON file. According to the documentation from the site, below is to be used in the Post body:

{
"vectorIds": ["74804","1"],
"startDataPointReleaseDate": "2015-12-01T08:30",
"endDataPointReleaseDate": "2018-03-31T19:00"
}

What I have tried:

I think the issue is with the array in the first part. From what I have been able to find you use brackets for arrays and I have tried every way I can think of but I keep getting
the following:

406{"message":"JSON syntax error, please refer to the manual to check the input JSON content"}

Here is one of the ways I have tried in my VBNET code:
Jsonstring = "[{""vectorIds"": [""74804"" , ""1""],""startDataPointReleaseDate"":""2015-12-01T08:30"",""endDataPointReleaseDate"":""2018-03-31T19:00""}]"

The URL is https://www150.statcan.gc.ca/t1/wds/rest/getBulkVectorDataByRange

I was successful in other API calls for this URL but I cannot get this one to work. Any help or suggestions would be greatly appreciated.
Posted
Updated 15-Mar-22 4:03am
Comments
Richard MacCutchan 15-Mar-22 8:35am    
You need to contact the owners of the website, they will know why that response is being generated.

Jsonstring = "[{""vectorIds"": [""74804"" , ""1""],""startDataPointReleaseDate"":""2015-12-01T08:30"",""endDataPointReleaseDate"":""2018-03-31T19:00""}]"

You need to remove the beginning and ending square brackets from your string. The example at Web Data Service (WDS) User Guide[^] clearly shows that you are to send a single JSON item, not an array.
 
Share this answer
 
Start here: JSON Utils: Generate C#, VB.Net, SQL TAble and Java from JSON[^] - you feed it JSON data, it generates classes that can hold that data.

Your first example is valid JSON, and requires classes like this:
{
"vectorIds": ["74804","1"],
"startDataPointReleaseDate": "2015-12-01T08:30",
"endDataPointReleaseDate": "2018-03-31T19:00"
}

VB
Public Class Example
    Public Property vectorIds As String()
    Public Property startDataPointReleaseDate As String
    Public Property endDataPointReleaseDate As String
End Class
Your second JSON example is also valid:
[{"vectorIds": ["74804" , "1"],"startDataPointReleaseDate":"2015-12-01T08:30","endDataPointReleaseDate":"2018-03-31T19:00"}]
and uses the same classes.

So the problem is more likely to be that the data you get from your URL isn't valid JSON, or isn't "just" JSON.

Use the debugger to find out exactly what is returned by the URL, and try feeding that into a class generator to compare with what you expect.
 
Share this answer
 
Thanks to all. The suggestion from Richard to remove the beginning and ending square brackets from the string worked. Although, I am not really sure why. I successfully used them in another API on this URL

Jsonstring = "[{""vectorId"": 41692894,""latestN"":10}]"

It must be because of the array, I am guessing. Thanks for the help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900