大约一年前,我在C#中创建了一个代码,用于使用RestClient反序列化Json API。 现在我想用Java实现它与Jenkins的集成。 基本上我想使用API响应正文来获取数据并自动调用其他API 。
以下是我在c#
中创建的代码using System;
using Android.App;
using Android.Widget;
using Android.OS;
using RestSharp;
using Newtonsoft.Json;
using App4.Resources;
using System.Collections.Generic;
using System.Threading;
namespace App4
{
[Activity(Label = "Whirlpool Consulta de API", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
EditText edtcpf;
Button btnConsumer;
TextView txtcpf;
RestRequest cpf { get; set; }
public RestClient consumer { get; set; }
IRestResponse mensagemConsumer;
RestClient orderId { get; set; }
RestRequest requestorderId { get; set; }
IRestResponse answerorder { get; set; }
TextView txtnome;
public List<string> lista;
ListView mlistview;
private ProgressDialog mProgressDialog;
// ImageView imageView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
txtcpf = FindViewById<TextView>(Resource.Id.txtcpf);
mlistview = FindViewById<ListView>(Resource.Id.listView2);
txtnome = FindViewById<TextView>(Resource.Id.txtNome);
edtcpf = FindViewById<EditText>(Resource.Id.edtcpf);
btnConsumer = FindViewById<Button>(Resource.Id.btnConsumer);
//imageView = FindViewById<ImageView>(Resource.Id.imageView1);
btnConsumer.Click += BtnConsumer_Click;
lista = new List<string>();
}
private void BtnConsumer_Click(object sender, EventArgs e)
{
// API Consumer CPF
/* ProgressDialog progress = new ProgressDialog(this);
progress.Indeterminate = true;
progress.SetProgressStyle(ProgressDialogStyle.Spinner);
progress.SetMessage("Carregando. Por favor aguarde...");
//progress.SetCancelable(false);
progress.Show();*/
try
{
var limpa = "";
showbox("Iniciando Pesquisa...");
consumer = new RestClient("https://qa.api-latam.whirlpool.com/v1.0/consumers");
cpf = new RestRequest("/" + edtcpf.Text, Method.GET);
cpf.AddHeader("Content-Type", "application/json; charset=utf-8");
cpf.AddHeader("Authorization", "Bearer fed6b2f0-7aba-3339-9813-7fc9387e2581");
mensagemConsumer = consumer.Execute(cpf);
Pessoa pessoa = JsonConvert.DeserializeObject<Pessoa>(mensagemConsumer.Content);
txtnome.Text = "Nome: " + pessoa.firstName + " " + pessoa.lastName
这是我想要转换为Java的代码。难吗?如何使用API响应来调用另一个API?例如:获取用户ID并将其作为参数发送到另一个API中。
此致 卢卡斯