zoukankan      html  css  js  c++  java
  • 使用JSON

    软件152 苏锐

    在JavaScript中使用:

    <script>
        function test()
        {
            //json 对象
            var peoper = {
            p:[
            {"name":"kay","sex":"man","age":"22"},
            {"name":"Rose","sex":"girl","age":"21"}
            ]};
            alert(peoper.p[0].name); //value  kay
            alert(peoper.p[1].sex); //value girl
            //修改值
            peoper.p[0].age = "55";
            peoper.p[0].name = "FanKai";
            
            alert(peoper.p[0].name); //value  FanKai
            alert(peoper.p[0].age); //value 55

            //var ss = peoper.toJSONString();
            alert(peoper);

        }
    </script>


    在Action(Servlet)中使用JSON:

        String js = request.getParameter("json");
            try
            {
                JSONObject json = new JSONObject(js);
                System.out.println("姓名:"+json.getString("name"));
                System.out.println("性别:"+json.getString("sex"));
            }
            catch (JSONException e)
            {
                e.printStackTrace();
            }

    给客户端发送JSON:

    JSONObject json = new JSONObject();
    json.append("name", "kay");
    json.append("sex", "boy");
    response.getWriter().print(json.toString());    
  • 相关阅读:
    小网络的激活函数
    Dual Path Networks
    RT600之Mailbox
    RT600之OTFAD
    RSA算法详解
    RT600之SB
    RT600之master key
    RT600之PUF
    RT600 Boot详解
    RT如何生成image
  • 原文地址:https://www.cnblogs.com/RiXun/p/7107094.html
Copyright © 2011-2022 走看看