-
Notifications
You must be signed in to change notification settings - Fork 362
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
Is there a more elegant implementation of re-serialization after partial modification of the contents of ast.Node? #588
Comments
|
|
No another points, just I wanna know this: how to get |
I mean its practical meaning, as a reference to support or not |
Tip:
So I guess |
OK. Looks like it's worth doing that. Let me add a new API to support it -- or can you try to submit a PR for this? |
It looks like only one or two lines need to be changed to support this feature. // IndexOrGet firstly use idx to index a value and check if its key matches
// If not, then use the key to search value
func (self *Node) IndexOrGet(idx int, key string) *Node {
if err := self.should(types.V_OBJECT, "an object"); err != nil {
return unwrapError(err)
}
pr := self.skipIndexPair(idx)
if pr != nil && pr.Key == key {
return &pr.Value
}
n, _ := self.skipKey(key)
return n
}
Should we directly add a return value to this method? Or is it better to create a new method to handle this logic? If we are to create a new method, what should the method name be? |
A new method, to keep compatible with elder version. Give any name you like, just make it easy to understand |
close via #594 |
Example data:
This is my
traveling
code:If use
ListIterator
, the copy of node will not change the source 'root' json content, onlyForEach
works but I only to particially update the keythumbnail
, no need to load another content.V_ARRAY
and edit its object's member?IndexOrGet
? For example, I wanna knowthumbnail
's index after callingIndexOrGet(5, "thumbnail")
.The text was updated successfully, but these errors were encountered: