比如我有一串字符串格式的URL,例如下边这样:
%5B%7B%22ip%22%3A%22119.90.49.95%22%2C%22port%22%3A%228074%22%7D%2C%7B%22ip%22%3A%22119.90.49.110%22%2C%22port%22%3A%228050%22%7D%2C%7B%22ip%22%3A%22119.90.49.92%22%2C%22port%22%3A%228057%22%7D%2C%7B%22ip%22%3A%22119.90.49.104%22%2C%22port%22%3A%228016%22%7D%2C%7B%22ip%22%3A%22119.90.49.104%22%2C%22port%22%3A%228017%22%7D%2C%7B%22ip%22%3A%22119.90.49.102%22%2C%22port%22%3A%228007%22%7D%2C%7B%22ip%22%3A%22119.90.49.107%22%2C%22port%22%3A%228034%22%7D%2C%7B%22ip%22%3A%22119.90.49.110%22%2C%22port%22%3A%228049%22%7D%2C%7B%22ip%22%3A%22119.90.49.91%22%2C%22port%22%3A%228053%22%7D%2C%7B%22ip%22%3A%22119.90.49.94%22%2C%22port%22%3A%228069%22%7D%5D
我想通过类似urldecode这样的函数转化为下边这样的形式:
```[{"ip":"119.90.49.95","port":"8074"},{"ip":"119.90.49.110","port":"8050"},{"ip":"119.90.49.92","port":"8057"},{"ip":"119.90.49.104","port":"8016"},{"ip":"119.90.49.104","port":"8017"},{"ip":"119.90.49.102","port":"8007"},{"ip":"119.90.49.107","port":"8034"},{"ip":"119.90.49.110","port":"8049"},{"ip":"119.90.49.91","port":"8053"},{"ip":"119.90.49.94","port":"8069"}]```
百度了好久也没找到GO中有类似的函数或者是库,难道这个问题不会经常用到么,,,还望大神解决
更多评论
有事没事别用百度, 直接查godoc就行了.
```go
package main
import(
"fmt"
"net/url"
)
func main(){
var URL = "%5B%7B%22ip%22%3A%22119.90.49.95%22%2C%22port%22%3A%228074%22%7D%2C%7B%22ip%22%3A%22119.90.49.110%22%2C%22port%22%3A%228050%22%7D%2C%7B%22ip%22%3A%22119.90.49.92%22%2C%22port%22%3A%228057%22%7D%2C%7B%22ip%22%3A%22119.90.49.104%22%2C%22port%22%3A%228016%22%7D%2C%7B%22ip%22%3A%22119.90.49.104%22%2C%22port%22%3A%228017%22%7D%2C%7B%22ip%22%3A%22119.90.49.102%22%2C%22port%22%3A%228007%22%7D%2C%7B%22ip%22%3A%22119.90.49.107%22%2C%22port%22%3A%228034%22%7D%2C%7B%22ip%22%3A%22119.90.49.110%22%2C%22port%22%3A%228049%22%7D%2C%7B%22ip%22%3A%22119.90.49.91%22%2C%22port%22%3A%228053%22%7D%2C%7B%22ip%22%3A%22119.90.49.94%22%2C%22port%22%3A%228069%22%7D%5D"
res, err := url.QueryUnescape(URL)
if nil != err {
fmt.Println(err)
return
}
fmt.Println(res)
}
```
#1