dongmeiran609914 2015-09-28 07:01
浏览 135

如何在Golang中使用jsonrpc包从服务器向客户端发送嵌套地图?

I am writing a client server go application which uses yahoo finance api to fetch the real time stock price. I am using jsonrpc package to connect client and server. I am unable to pass a nested map response from server to client. Here is my small snippet from the client file. client.go file

var (
        reply map[string]map[int]float64
    )

    c := jsonrpc.NewClient(client)
    err = c.Call("JSONResponse.GetStockValue", args, &reply)
    fmt.Println(reply)

Server file looks like this:

func (j *JSONResponse) GetStockValue(args *ClientRequest, reply *map[string]map[int]float64) error {
 some piece of code......
 nestedMap := make(map[string]map[int]float64)
 add some values in nested map .....
 fmt.Println(nestedMap)
 *reply = nestedMap
  return nil
}

This does not send any response to the client. When i change the nested map to simple map like map[string]int, it correctly works. The nested map is correctly displayed at server but does not get displayed on the client side. The client simply keeps on waiting for the response from the server. It would be very helpful if someone could guide me on why it is not accepting a nested map and working fine for a simple map ?

Thanks :)

  • 写回答

2条回答 默认 最新

  • duanchi4544 2015-09-29 01:21
    关注

    jsonrpc is json rpc because it use json for serialization. to Marshal a map to json, you need string key type. refer to encoding/json

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序