golang python 对比 转json格式字符串

 小结:

1、go排序

python 默认不排序,排序需显示指明

 

 

   jsonString, _ := json.Marshal(v)
 

\Go\src\encoding\json\encode.go

 

// Map values encode as JSON objects. The map's key type must either be a
// string, an integer type, or implement [encoding.TextMarshaler]. The map keys
// are sorted and used as JSON object keys by applying the following rules,
// subject to the UTF-8 coercion described for string values above:
//   - keys of any string type are used directly
//   - [encoding.TextMarshalers] are marshaled
//   - integer keys are converted to strings
 
 

 

 
 json.dumps
 
If *sort_keys* is true (default: ``False``), then the output of
dictionaries will be sorted by key.

def dumps(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None,
default=None, sort_keys=False, **kw):


posted @ 2024-07-23 14:36  papering  阅读(5)  评论(0编辑  收藏  举报