I have the following code corresponding to a file json
that I found in a question in this forum:
{
"Head" : {
"RequestArguments" : {
"DataCollection" : "",
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2016-06-20T08:15:41+02:00"
},
"Body" : {
"Data" : {
"PAC" : {
"Unit" : "W",
"Values" : {
"1" : 49
}
},
"DAY_ENERGY" : {
"Unit" : "Wh",
"Values" : {
"1" : 56
}
},
"YEAR_ENERGY" : {
"Unit" : "Wh",
"Values" : {
"1" : 771939
}
},
"TOTAL_ENERGY" : {
"Unit" : "Wh",
"Values" : {
"1" : 3246052
}
}
}
}
The JSON request returns that information and I'd like to know in advance the structure that a particular URL would return.
There is a web application that, with an example of your json file or the url to which you are going to make the request, converts the objects contained in that API to simple java code: http://json2java.azurewebsites.net/
I took this link from a similar one in a similar question for C# .
When you use it, you
JSON
normally do so by consuming an API that you know, either internal (made by you) or from an external developer, in these cases the structure does not usually change without prior notice, since if it were changed it would stop working where those APIs were being used.In your case, I don't know where the is from,
JSON
but if you don't know the structure it will return, you won't be able to read the data that interests you.For example, if
id:
they change it toid_usuario:
you have no way of identifying the field. With which if they tend to change the structure... You will have to be attentive and redesign your code.