I have to get weather forecast for 7 days of a particular location(with postal code 94042). For this I make a HTTP request like this:
http://api.openweathermap.org/data/2.5/forecast/daily?q=94042&mode=json&units=metric&cnt=7
The result of the query is a long string in Json format. I did not post the result as it is messy, you can click the link to view the result:
There are some parts of the result about which I am confused.
What does the dt field in the beginning of every element of the array list signify?
What does the second last field deg of every element in the array list signify?
What does the last field clouds followed by an integer signify? I thought description about clouds was covered in the main field?
Explanation of the parameters: http://openweathermap.org/weather-data#current
dt: Data receiving time (in unix, UTC format). dt is the time of data receiving in unixtime GMT (greenwich mean time). To convert this value, use a 3rd-party library like momentjs.com or refer to this answer on how to convert it: https://stackoverflow.com/a/847196/3412545
deg: Wind direction (in degrees, meteorological)
clouds: cloudiness also known as cloud cover (in %)
Related
I did a GET a minute ago, and this json was the result:
'[{"initialTreatment":"1","finalTreatment":"24","totalTreatments":"24","uniqueWellId":"051234644200100619153738"}]'
I turned around and tried to PUT this same json back and it tells me it "Cannot deserialize the current JSON array (e.g. [1,2,3])", etc.etc. It's not a list or array. It's a simple string. The object I am trying to deserialize to is exactly the same four properties, but I changed the first char to lowercase, although I have tried it with the original casing with the same result. I don't know what else I can try! I can't imagine a more simple request. I must not be holding my top lip right. Any help/suggestions would be appreciated.
oh, never mind. Apparently, it only likes [] if it is actually an array.
Thanks everyone.
I have a HTML table which renders one big JSON object of 1 MB file, I would like inform user that how big the object was and how much time it took to display data in Angular 6 application, any pointer please.
The incoming data could be vary based on service.
The line should say, the object which was binded to table HTML was x MB and it took y second to load data after table finishes of displaying data in HTML.
In face we are doing performance testing of big objects so based on that we are gonna do some stuff from services.
Create variable with current time before making request do API, something like
const requestStart = new Date()
Make request
When response return from API, get Content-Length header (I don't know what library you use to get requests, so I cannot help with how to get headers from it) and assign it to some another variable - it will give you file size
Subtract current date with requestStart date - it will give you time difference
I have a very long string of characters that contain a date and time. How can I extract just the date part and the time part from it?
Here's the string:
0:2019010309130000:0.000000:126:0
I just need to extract the date and the time as in:
Date - 20190103
Time - 0913 and format it as 09:13
This applies to Python programming language.:
If the string stays in the same format I believe you should be able to extract it using a concept known as "slicing" (you can find more about it in here).
x = "0:2019010309130000:0.000000:126:0"
y = 'Date - {} Time - {}:{}'.format(x[2:10], x[10:12], x[12:14])
print(y)
I'm using jsoncpp to store information in JSON format. I now have the need to store a json string inside of another json string... In other words, I need to store a sub_item inside of an item.
Using jsoncpp to generate the JSON string, I get this...
{"id":"1","name":"Advil","sub_item":"{\"id\":\"2\",\"name\":\"Liquid Gel Advil\"}\n"}
Which works perfectly fine during runtime. However, when my program saves this information into a MySQL database (on exit) and then loads it back up when I restart the program, it loads the same JSON string from the MySQL database, but it now looks like this...
{"id":"1","name":"Advil","sub_item":"{"id":"2","name":"Liquid Gel Advil"}"}
Which is an invalid JSON string. I'm not sure why this is happening can someone please tell me what the heck is going on...
My MySQL query string reads like so:
UPDATE json_string_test SET jsonstring='{"id":"1","name":"Advil","sub_item":"{\"id\":\"2\",\"name\":\"Liquid Gel Advil\"}\n"}';
Upon further research I found out FastWriter was depreciated, and StreamWriterBuilder was the recommended writer. However, it still produced the same problem as FastWrtier....
I managed to rig a fix by doing the following...
1) Before saving to the database, I replaced ALL substrings matching \" to \\" in ONLY the child JSON string (with id 2).
2) Upon loading the JSON string, I replaced ALL substrings matching \\" to \" in ONLY the child JSON string (with id 2).
I don't understand why the heck I have to do this, so if anyone has a better solution or an explanation... I'd love to hear it.
I think you need to transpose your last 2 characters (assuming your posted string is verbatim). You have
Advil\"}\n"}
but I think you need
Advil\"}\n}"
Has anyone else seen this or can you verify seeing this behavior?
I'm using PayPal's new REST API. It is a fact that some CVV numbers on credit card start with a 0 (zero). Yet sending a request to the PayPal REST API with a CVV number starting with zero fails. This is because the "cvv2" value within a "funding_instrument" object is expected to be a number and a number starting with zero is invalid JSON. When I try to execute my request anyway I get a "INTERNAL_SERVICE_ERROR" error as my response.
In an attempt to correct this I wrapped my CVV number in quotation marks to treat it as a string and then resubmitted my request. This time I get a "VALIDATION_ERROR" response telling me that the CVV number must be numeric. So unless there's some way to escape a leading zero in a number in JSON there's no way to accept cards via PayPal REST API where the CVV contains a zero as its first digit.
Any help?
This is a bug in our new REST API - where the cvv2 field is defined as an integer instead of a string to accomodate the values that begin with zeros (eg. 011, 001). We are working the fix - will update this thread once the fix is rolled out.
The only integer whose decimal representation starts with a "0" is zero, which is perfectly legal in JSON. The problem you describe is impossible. You do have to convert the CVV2 code from whatever representation you have to a canonical decimal number because that is required by the JSON specification.
You never actually got the CVV number from the user (or whatever the source is). You tried to convert the representation directly into JSON. Converting representations directly will get you into trouble -- instead convert through numbers.
"012" on a credit card represents the number twelve. The number twelve is represented in JSON was "12". When trying to convert a number from one representation to another, it's almost always best to convert it to a number first.
"012" is not a legal representation of any number according to the JSON specification. Trying to send it violates that specification and indicates you never actually got the CVV number but instead tried to use its representation as if it was the number represented. This is like eating a recipe and is likely to give you, and the PayPal API, indigestion.
Update: Apparently, the bug is in the PayPal API. CVV codes are not numbers. There is no such thing as a "CVV number". The PayPal API requires you to supply something that does not exist and fails when there is no number that corresponds to the CVV code.