| 156 | } |
| 157 | |
| 158 | function _encode(sub, path) { |
| 159 | var encode = that.encode; |
| 160 | var type = that.type(sub); |
| 161 | if (type == "array") { |
| 162 | sub.forEach(function (e, i) { |
| 163 | if (!that.isObject(e)) i = ""; |
| 164 | _encode(e, path + ('%5B' + i + '%5D')); |
| 165 | }); |
| 166 | } else if (type == "object") { |
| 167 | for (var key in sub) { |
| 168 | if (path) { |
| 169 | _encode(sub[key], path + "%5B" + encode(key) + "%5D"); |
| 170 | } else { |
| 171 | _encode(sub[key], encode(key)); |
| 172 | } |
| 173 | } |
| 174 | } else { |
| 175 | if (!first) { |
| 176 | str += "&"; |
| 177 | } |
| 178 | first = false; |
| 179 | str += path + "=" + encode(sub); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | _encode(data, ""); |
| 184 | return str; |