New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/url: Stitching complex arrays #29703
Comments
It is not clear to me how you want the net/url package to help here. Why can't you just do -
That prints m, err := url.ParseQuery(`b=%7B%22c%22%3A%22c%22%7D`)
if err != nil {
log.Fatal(err)
}
fmt.Println(m) // map[b:[{"c":"c"}]] |
I want to user[name]=&user[age]=test2&user[sex]=test3 like PHP example http_build_query() with complex arrays <?php
$data = array(
'user' => array(
'name' => 'Bob Smith',
'age' => 47,
'sex' => 'M',
'dob' => '5/12/1956'
),
'pastimes' => array('golf', 'opera', 'poker', 'rap'),
'children' => array(
'bobby' => array('age'=>12, 'sex'=>'M'),
'sally' => array('age'=>8, 'sex'=>'F')
),
'CEO'
);
echo http_build_query($data, 'flags_');
?> this will output : (word wrapped for readability) user[name]=Bob+Smith&user[age]=47&user[sex]=M&
user[dob]=5/12/1956&pastimes[0]=golf&pastimes[1]=opera&
pastimes[2]=poker&pastimes[3]=rap&children[bobby][age]=12&
children[bobby][sex]=M&children[sally][age]=8&
children[sally][sex]=F&flags_0=CEO |
Thanks for the clarification. It would have helped if you would have mentioned this in the first place up-front. I think you will have to write your own logic to parse the json and build your query keys, or use some external library which can help you to easily iterate nested keys. If you would want something like this to be in the standard library, please open a separate proposal issue clealy mentioning why you want something like this in the standard library (also see - https://golang.org/doc/faq#x_in_std). |
thanks |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I want to get a query string.
If like this,I can
Bug if complex arrays,like this
The text was updated successfully, but these errors were encountered: