Skip to content
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

Can parse Wikipedia response #93

Closed
tapir opened this issue Mar 2, 2017 · 1 comment
Closed

Can parse Wikipedia response #93

tapir opened this issue Mar 2, 2017 · 1 comment

Comments

@tapir
Copy link

tapir commented Mar 2, 2017

Here is a code to reproduce

package main

import (
	"github.com/buger/jsonparser"
	"fmt"
)

func main() {
	body := []byte(`["api",["Application programming interface"],["In computer programming, an application programming interface (API) is a set of subroutine definitions, protocols, and tools for building application software."],["https://en.wikipedia.org/wiki/Application_programming_interface"]]`)
	jsonparser.ArrayEach(body, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
		a, err := jsonparser.GetString(value, "[0]")
		if err == nil {
			fmt.Println(a)
		} else {
			fmt.Println(err)
		}
	})
}

The JSON comes directly from wikipedia. The first element of the array is not an array so I get why "Key path not found" is correct in that case but the other 3 are arrays with single element which is a string. I get "Unknown value type" for those.

@buger
Copy link
Owner

buger commented Jun 3, 2017

You probably want to do: a, err := GetString(body, "[1]", "[0]") instead. Which will get 'Application programming interface' string.

@buger buger closed this as completed Jun 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants