douju1928 2019-01-08 09:31
浏览 12
已采纳

如何将字符串转换为JSON obj? [重复]

This question already has an answer here:

Below is the code that I've tried but to no avail:

    jsonObj, err := json.Marshal(supportJSONString)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
    }
    fmt.Fprintf(w, "%s", jsonObj)
</div>
  • 写回答

1条回答 默认 最新

  • douman6245 2019-01-08 09:35
    关注

    Its already a json object. All you need to do is

    jsonObj := []byte(supportJsonString)
    

    You can then return it as HTTP response. But in the most generic case, you would want to create a struct as response object and the marshal it to json instead of using strings this way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?