简体   繁体   English

Node.js + Android客户端+ JSON文件上的服务器

[英]Server on node.js + android client + json file

I have a RESTful API on Node.js that works with a json file. 我在Node.js上有一个RESTful API,可与json文件一起使用。 The problem lies in the fact that it does not come out to write a simple android client (previously it did not work with Java and in the android studio for the first time), which could work with the api of my server, or rather change this json file itself: 问题在于无法编写一个简单的android客户端(以前它不能在Java和android studio中第一次使用),而这可以与我服务器的api一起使用,甚至可以更改这个json文件本身:

[{"id":1,"name":"Tom","password":24},{"id":2,"name":"Bob","password":27},{"id":3,"name":"Alice","password":"23"}].

I read both about gson and valley and httpurlconnection, but in the end it does not work even just to connect to the server, there is no understanding of how to do it correctly. 我读了有关gson和valley和httpurlconnection的文章,但最后,即使仅连接到服务器也无法正常工作,对如何正确执行它也没有任何了解。

I ask for help with writing code, links to useful articles, or just advice. 我在编写代码,指向有用文章的链接或只是建议方面寻求帮助。

Ps The server-client experience is only from Qt, there with sockets somehow it was easier .... Ps服务器-客户端体验仅来自Qt,那里的套接字以某种方式更容易....

I apologize for my english, thank you, google translate 我为我的英语表示歉意,谢谢,谷歌翻译

if I get you correctly, you want to get this data in your android app if that so i recommend using Retrofit you should made an Interface class first then add something like this in your Interface: 如果我正确地理解了您,那么您想在Android应用程序中获取此数据,因此,我建议您使用Retrofit,首先应该制作一个Interface类,然后在Interface中添加如下内容:

 @GET("yourapi.com/url")
    Call<YourDataModelClass> GET_MY_DATA(
            @Header("Authorization") String key);

and please be aware that you should add what your api requires too, I've only added header here for just an example. 并且请注意,您也应该添加您的api所需的内容,我仅在此处添加了标题,仅作为示例。

then in your data model Class, you should add something like this: 然后在数据模型类中,应添加如下内容:

public class YourDataModelClass {
    private Boolean action;
    private String _token;
    private boolean need_login;
    private int id;
    private String name;
    private String password;

    public boolean isNeed_login() {
        return need_login;
    }

    public Boolean getAction() {
        return action;
    }

    public String get_token() {
        return _token;
    }
    public String password() {
        return password;
    }
     public String name() {
         return name;
    }
    public int id() {
        return id;
    }
}

let me know how it goes. 让我知道事情的后续。 and goodluck 还有祝你好运

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

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