Its possible send array in url - java

I would like to know if i can send an array of this type endate [] in the parameter fecha2 of the following url:
http://www.xxxx.com/app/disponibilidad?idUser&fecha2&fecha1&desde&hasta
endate[] has several date I want to send in a single url. I would like to know if that is possible

You can get a good idea in How to pass an array within a query string?
You can also encode it to JSON and pass it as a single string, then decode it on your backend. Sounds simpler to me.

Related

How to post multiple values at same key using Retrofit 2?

I am stuck on this part which requires me to post multiple values to the server. I am using Retrofit.
The whole scenario is like this: there is a form where user can fill in the details like his name, age, address and can even select multiple values from certain questions. Particularly, there are 5 types of questions: Int, String, Single Choice, Boolean and Multiple Choice. As you can see I can have Int, String, Boolean and Array types.
So I created FieldMap as > to save all values in it and then posting it. I am able to post all values except Array which my server is expecting as query dict i.e. if I have FieldMap as "143": ["hello", "hey", "hi"]; server is expecting me to send it as 143=hello&143=hey&143=hi.
It is expecting me to send all array values to same key as shown above.
Can somebody help me with this? How can I achieve this using Retrofit 2?
Have you tried sth like following?
#GET("endpoint")
fun getSomething(#Query("143") items: List<String>): Call<Response>

Parse json string of the underline format to compare the values with another map

I have a JSON string that looks like:
"{\"info\":{\"length\":{\"value\":18},\"name\":{\"value\":\"ABC\"}}}"
say, length and name are attribute names
I have another map (say attributeMap) that (created from the results I retrieve from the database) map has attribute name and attribute value association stored.
I need to be able to parse the string and compare the value an attribute has in the above string with the value returned from the attributeMap. Based on those comparisons, I will need to take some decisions.
In order to do this, I should convert the above string to a format that would help make the above comparison easier and efficient. I don't think I should be writing my own parser to do this. what would a right way to do this?
You should use any JSON Parser, like GSON (Google) (Recommended for simplicity), JACKSON, the simple org.json, or any other..
Then you will get a JSONObject/JSONNode to navigate and do the comparison.
You can find a parsing example here: How to parse JSON in Java

How to get json as a string from a url?

I want to have an array with the value of json:
arr[ ] array = {"http://www.ip-api.com/json"};
when I print this array, how can I have json but not "http://www.ip-api.com/json" as a string?
Use a JSON generating library such as Jackson and have it serialize the data structure.
https://github.com/FasterXML/jackson
If you want to actually mean that you want to call the service at that URL then you need to use a suitable library for that...

In Java, how do I retrieve the data values from the xml and store them in an array?

this is my xml file
<waveform>
<Ivalue>12,13,14,15,16,17,18</Ivalue>
<IIvalue>1,4,15,23,22,44</IIvalue>
</waveform>
<waveform>
<Ivalue>12,13,14,15,16,17,18</Ivalue>
<IIvalue>1,4,15,23,22,44</IIvalue>
</waveform>
here, I know how to retrieve the values by tags but is it possible to store these values into separate int[]?
Thanks
You may use JAXB for extracting tags like Ivalue AS STRING.
To my knowledge it is at least not easy to get it directly as int array (with JAXB)
However, it is easy to split the string using String.split and convert the results with
Integer.parse

Java HTTP Get Request

I need to make one HTTP GET Request to a Java Web Service:
I'm making this request:
http://127.0.0.1:8080/MyService/services/service?method=myMethod&a=&b=test&startDate=2011-03-10 10:00&endDate=2011-03-10 19:00
When I Debug my app the parameters come with the values switched. I already tried to encode the startDate and endDate parameters but the result is the same.
What am i doing wrong?
You should encode your URLs so they don't contain spaces. This could be your problem. See http://download.oracle.com/javase/1.5.0/docs/api/java/net/URLEncoder.html
As #Mirkules says, you should encode the spaces and colons in the parameter values ... even if you don't think it makes any difference!
Apart from that, maybe your servlet code is expecting Request.getParameters() to deliver the parameters in the order that they appear in the URL. This is not the case. If order of the parameters is significant, you need to parse the query string yourself. (Or consider fixing your web API so that the query parameter order is irrelevant.)

Categories