阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      插件 jQuery.io 中文 API 文档

      插件 jQuery.io 中文 API 文档

      用于在不同格式之间转换数据的 jQuery 插件:

      • JavaScript 对象
      • HTML 表单
      • json 字符串
      • 查询字符串
      • 转换表单

      到 JavaScript 对象

      $.io.form($('form')).object();
      
      {
      	user: {
      		name: 'Sam',
      		interests: ['1', '2']
      	}
      }
      

      到查询字符串

      $.io.form($('form')).query();
      
      'user%5Bname%5D=Sam&user%5Binterests%5D%5B%5D=1&user%5Binterests%5D%5B%5D=2'
      
      // this is equivalent to:
      
      $('form').serialize();
      

      到一个 json 字符串

      $.io.form($('form')).json();
      
      '{"user":{"id":"1","name":"Sam","interests":["1","2","3"]}}'
      

      转换查询字符串

      到 JavaScript 对象

      var source = 'user%5Bname%5D=Sam&user%5Binterests%5D%5B%5D=1&user%5Binterests%5D%5B%5D=2';
      $.io.query(source).object();
      
      {
      	user: {
      		name: 'Sam',
      		interests: ['1', '2']
      	}
      }
      

      到一个 json 字符串

      var source = 'user%5Bname%5D=Sam&user%5Binterests%5D%5B%5D=1&user%5Binterests%5D%5B%5D=2';
      $.io.query(source).json();
      
      '{"user":{"id":"1","name":"Sam","interests":["1","2","3"]}}'
      
      

      转换 Json

      到 JS 对象

      var source = '{"user":{"id":"1","name":"Sam","interests":["1","2","3"]}}';
      $.io.json(source).object();
      
      {
      	user: {
      		name: 'Sam',
      		interests: ['1', '2']
      	}
      }
      
      // this is equivalent to:
      JSON.parse(source)
      
      

      到查询字符串

      var source = '{"user":{"id":"1","name":"Sam","interests":["1","2","3"]}}';
      $.io.json(source).query();
      
      'user%5Bname%5D=Sam&user%5Binterests%5D%5B%5D=1&user%5Binterests%5D%5B%5D=2'
      
      

      转换 JavaScript 对象

      到查询字符串

      var source = 	{
      	user: {
      		name: 'Sam',
      		interests: ['1', '2']
      	}
      }
      $.io.object(source).query();
      
      'user%5Bname%5D=Sam&user%5Binterests%5D%5B%5D=1&user%5Binterests%5D%5B%5D=2'
      
      

      到一个 json 字符串

      var source = 	{
      	user: {
      		name: 'Sam',
      		interests: ['1', '2']
      	}
      }
      
      $.io.object(source).json();
      
      '{"user":{"id":"1","name":"Sam","interests":["1","2","3"]}}'
      
      // this is equivalent to:
      JSON.stringify(source);
      
      

      Limits

      给定像&a = 101 这样的查询,目前 io 不会试图弄清楚 101 是数字还是字符串,所以如果转换为对象,它将只返回一个字符串。例如{a:‘101’}

      目录
      目录