简体   繁体   English

解析JSON响应REST android

[英]Parse JSON Response REST android

I am new to android annotation , i have multiple confusions regarding REST client implementation of AA api.Here is my code i am using: 我是android注解的新手,关于AA api的REST客户端实现我有很多困惑。这是我正在使用的代码:

@Rest(rootUrl = "http://something.com", converters = {MappingJackson2HttpMessageConverter.class})

public // if defined, the url will be added as a prefix to every request
interface RESTClient extends RestClientHeaders {
    @Post("/isec/api/user/login ")
    @Accept(MediaType.APPLICATION_JSON)
    void LoginUser(@Field String email,@Field String password,@Field String type);
}

and Expected JSON response is : 预期的JSON响应为:

{
"status": false
"message": "Verify your account to continue"
"verified": "n"
"type": "STUDENT"
"apikey": "4o0k8sg4g8ckkswskkowcog80gog4gso0g00kogo"
}

Now my questions are : 现在我的问题是:

1 - In which variable i get the response JSON ? 1-我在哪个变量中获得响应JSON

2 - What is the best possible way to Parse my response JSON , because i get different responses on different parameters of same URL , so i cannot create a class to deal with response ? 2-解析响应JSON的最佳方法是什么,因为我在同一URL的不同参数上获得不同的响应,因此无法创建一个用于处理响应的类?

3 - What is main difference between @Path , @field annotation ? 3 -之间的主要区别是什么@Path@field注释?

thanks in advance 提前致谢

@Rest(rootUrl = "http://something.com", converters = {MappingJackson2HttpMessageConverter.class})

public // if defined, the url will be added as a prefix to every request
interface RESTClient extends RestClientHeaders {
    @Post("/isec/api/user/login ")
    @Accept(MediaType.APPLICATION_JSON)
    YourResponseClass LoginUser(@Field String email,@Field String password,@Field String type);
}

The response will be parsed into your class with Jackson in this case. 在这种情况下,响应将与Jackson一起解析到您的班级中。

@Path is for url variables, @Field is for form inputs. @Path用于url变量, @Field用于表单输入。 The first are substitued into the URL, the second is added in the request body as form url encoded parameters. 第一个被替换为URL,第二个被作为表单url编码参数添加到请求正文中。 Please read the wiki, it has detailed examples. 请阅读Wiki,其中包含详细示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM