ฉันกำลังเขียนเฟรมเวิร์กสำหรับ API บริการเว็บที่ส่งคืน json ฉันใช้ไลบรารี Jackson เพื่อดีซีเรียลไลซ์สตริง json API ส่งคืนคุณสมบัติเพื่อดึงผลลัพธ์ของคำขอต่อไป การตอบสนองเช่นนี้:
{
continueToken:"token",
results: [
{
},
]
}
คำตอบทั้งหมดมีโครงสร้างนี้ ปัญหาเดียวคือชื่อของคุณสมบัติ Continue นั้นแตกต่างจากคำขออื่น ชื่อก็ประมาณนี้
prefix + "continue"
ฉันต้องการสร้างเพียงคลาสเดียวและสามารถแมป json กับคลาสนี้ได้ ฉันจะทำเช่นนั้นได้อย่างไร? นี่คือสิ่งที่ฉันต้องการ:
public class Response {
private String continueToken;
private List<Article> results;
public Response (String continueToken, Article[] articles) {
this.continueToken = continueToken;
this.results = Arrays.asList(articles);
}
}
//Here the name is ttcontinue
String json = request.get(type1);
Response r = jsonToResponse(json);
//Here the name is llcontinue
json = request.get(type2);
r = jsonToResponse(json);
continueToken
แต่คำขอมีชื่อตัวแปรที่แตกต่างกันซึ่งจะต้องส่งผ่านcontinueToken
? คุณไม่สามารถนำโทเค็นจากการตอบกลับแล้วส่งผ่านไปยังตัวแปรที่ถูกต้องในคำขอแล้วทำให้เป็นอนุกรมไปยัง json ได้หรือไม่ - person Deepak Bala   schedule 06.01.2015