drwdvftp423507 2019-03-27 17:54
浏览 71
已采纳

JSON无法将对象解组为字符串类型的GO值

Writing Golang app using github.com/zserge/lorca package. This binds golang funcs to Javascript. I have HTML with text input and submit button which should pass the text input as an arg into the Javascript binding. It looks as follows:

<input type="text" name="MACADD" style="height:20px; width:210px">
<input type="submit" value="submit" onclick="JSBINDFUNC(MACADD)">

The JSBINDFUNC takes golang type string for input. When I hit submit, it should be passing the text entered for MACADD as an arg into the JSBINDFUNC func.

However, I'm coming back with the err

exception":{"type":"string","value":"json: cannot unmarshal object into Go value of type string"}

Needing this object to become golang string.

More complete snip:

package main

import (
    "fmt"
    "log"
    "net/url"

    "github.com/zserge/lorca"
)

func main() {
    ui, err := lorca.New("data:text/html,"+url.PathEscape(`
        <html>
                <form action="/action_page.php">
                    MAC Address:<br>
                    <input type="text" name="MACADD" style="height:20px; width:210px">
                    <input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD)">
                </form> 
            </body>
        </html>
        `), "", 480, 320)
    if err != nil {
        log.Fatal(err)
    }
    //ui.Bind implemented @ https://github.com/zserge/lorca/blob/master/ui.go#L110
    ui.Bind("JSBINDFUNC", func(MAC string) {
        fmt.Println(MAC)
        return
    })
    defer ui.Close()
    <-ui.Done()
}

  • 写回答

1条回答 默认 最新

  • dporb84480 2019-03-27 20:04
    关注

    The issue is with your javascript. Update your onclick attribute like so:

    <input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD.value)">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python