SO I am making a rest request to the JIRA API and getting a json response that includes all objects.
my request look like this:
Set restReq = CreateObject("MSXML2.ServerXMLHTTP.3.0")
restReq.open "GET", "URI",False
restReq.setRequestHeader "Authorization","Basic{user:Password}"
restReq.setOption SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS,SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
restReq.send("")
'response.write(restReq.responseText)
the response.write looks like this (but much longer):
[{"self":"https://JIRA:8343/rest/api/2/project/CT","id":"10004","key":"CT","name":"Core Technologies"}},
{"self":"https://JIRA:8343/rest/api/2/project/CTCCG","id":"10006","key":"CTCCG","name":"CT CCG"}}]
I would like to be able to loop through the response and use the "id", "key" and "name" in an unordered list. I can create a ul, but how do I extract the information I need from the json?
You check this question relating to using the Gson library . It is very small, quick and easy to use to convert between JSON to Objects.
import java.io.FileReader;
import com.google.gson.Gson;
public class Test {
public static void main(String[] args) throws Exception
{
Gson gson = new Gson();
TypeDTO[] myTypes = gson.fromJson(new FileReader("D:\\temp\\inputjson.txt"), TypeDTO[].class);
for (int i = 0; i < myTypes.length; ++i)
System.out.println(myTypes[i].self);
}
class TypeDTO
{
String self;
String id;
String key;
String name;
}
}
inputjson.txt had
[{"self":"https://JIRA:8343/rest/api/2/project/CT","id":"10004","key":"CT","name":"Core Technologies"},
{"self":"https://JIRA:8343/rest/api/2/project/CTCCG","id":"10006","key":"CTCCG","name":"CT CCG"}]
note the absence of addtional }
when compared to yours at the end of each line.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.