doumaogui5937 2016-06-10 18:10 采纳率: 100%
浏览 78

提前中止jsonparser中的ArrayEach回调

Looking at this callback (line 412), is it possible to break out of the callback loop from inside the callback function itself? Or would I need to wrap it or extend it in some way to create that capability?

This is the code:

jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
    if v, err := jsonparser.GetUnsafeString(value, "username"); nil == err && v == lookFor {
        z = v
        return // Abort in some way?
    }
})

The library is still waiting for a query-like update so for now this is the cheapest way to find a value, which still outperforms any full json parser by far (doing about 9.21x to 9.38x faster on benchmarks). So I'm kind of aiming for a LIMIT 1-ish solution.

I was thinking of doing a full copy-paste and making an cloned version on the interface and making..

if t != NotExist {
    cb(v, t, o, e)
}

into...

if t != NotExist {
    boolVal = cb(v, t, o, e) // Extending it to have a return value
}

... return a boolean and validate as a continue indicator. But would there be a more clean way without fully duplicating this code?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答