search

Home  >  Q&A  >  body text

android - Java后台把数据用json发到手机端,里面是map存放的,必须要说明数据的类型?

               List<HashMap> reList = new ArrayList<HashMap>();
                      for(int i=0;i<bjdList.size();i++){
                          Zqwl_yd_jdxx bjd = bjdList.get(i);
                          HashMap temp = new HashMap();
                          temp.put("id",bjd.getId());
                          temp.put("yd_number",bjd.getYd_number());
                          temp.put("status",bjd.getStatus());
                          reList.add(temp);
                      }
                
                 str = JSONValue.toJSONString(reList);
                 response.getWriter().write(str);

我写后台的接口,ios的程序员说必须标注每一个值得类型(string int 。。。)Android的程序员就不用?转正json返回之后不都是字符串了吗?为什么还要标注出int类型?

PHPzPHPz2891 days ago393

reply all(9)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:17:18

    Since it is an agreement, it must be agreed upon by both parties. It is best to have an interface document. Although json is just a string, the values ​​​​in it have different types. Android said that he does not need to mark it, maybe it is just that he thinks he can understand your json data. type (but not necessarily the data type that your backend originally wanted to give, for example, if you give it a float type, it uses double to get it. There is no difference for values ​​​​that do not require high precision), and iOS may want to be more clear and rigorous. , he wants to determine the exact value type. It must be unified at this time, otherwise you will not be able to explain clearly if there is a problem in the future.

    reply
    0
  • PHPz

    PHPz2017-04-18 09:17:18

    json is just a string.
    It’s not necessary. I didn’t have this kind of problem when connecting with ios programmers.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:17:18

    No need to mark ~

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:17:18

    I think it’s right for you to mark it.
    I have encountered problems with NSNumber and NSString that caused the program to crash

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:17:18

    Actually, JSON has a type. The expanded "" is a string. "value":"1" and "value":1 are different.
    Of course, IOS says it must be marked, but he doesn't want to Processing, I hope the background can handle it and use it directly, android just handles it for you.

    It doesn’t matter who is right or wrong, but who is willing to do more.

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:17:18

    The core of this problem lies in accurately understanding the definition of the JSON format
    Control characters in JSON
    {The beginning of the key-value pair container (A collection of name/value pairs)
    } The end of the key-value pair container
    [Array The beginning of the container
    ] The end of the array container
    : key-value pair delimiter
    " The beginning or end of the string
    , the delimiter inside the container
    The type of value in JSON
    string The part between two double quotes, official website The original text is a collection of any number of Unicode characters surrounded by double quotes, using backslash escape. A character (character), that is, a separate string, is represented in OC as an NSString object
    number with the character '0' or '9. ' at the beginning, the original text of the official website removes the unused octal and hexadecimal formats, and is represented in OC as an NSNumber object.
    object object type, and in OC is represented as an ordered list of NSDictionary
    values ​​(An ordered list of values ), commonly known as array, the performance in OC is NSArray
    null null object, empty object, the performance in OC is NSNull
    bool true/false Since there is no existence of Boolean objects in OC, the performance in OC is NSNumber

    You can watch my podcast
    http://cocoa1024.com/2016/03/31/stackjson/

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:17:18

    Json is just a format. You can treat it as a string when receiving it, but when parsing, the value is typed

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:17:18

    As for the oia document, if you don’t have oia, at least it must have json schema

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:17:18

    No need, map can also be parsed directly

    {"aaa,bbb";"aaa,bbb"}

       ArrayMap arrayMap = new ArrayMap();
          try {
               org.json.JSONObject obj = new org.json.JSONObject(content);
               Iterator<String> iterator = obj.keys();
               while (iterator.hasNext()) {
                   String key = iterator.next();
                   String value = (String) obj.get(key);
                   arrayMap.put(key, value);
                }
            } catch (JSONException e) {
                e.printStackTrace();
          }

    reply
    0
  • Cancelreply