How to call a json webservice through android

前端 未结 4 1053
不知归路
不知归路 2020-12-31 07:28

I need to access a .Net web service in Rest format using JSON. I m pretty new to this concept and very much confused about how this works.... Any one who can give an overvie

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 07:34

    Gson library can parse your json string automatically to object. Simple example:

     Gson gson = new Gson();
     int[] ints = {1, 2, 3, 4, 5};
     String[] strings = {"abc", "def", "ghi"};
    
     //(Serialization)
     gson.toJson(ints);     ==> prints [1,2,3,4,5]
     gson.toJson(strings);  ==> prints ["abc", "def", "ghi"]
    
     //(Deserialization)
     int[] ints2 = gson.fromJson("[1,2,3,4,5]", int[].class); 
     ==> ints2 will be same as ints
    

提交回复
热议问题