We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
import thriftpy2.protocol.json as thrift_json
param_obj = WordCloudParam(word_counts={'a': 10, 'b': 20}) param_json = thrift_json.struct_to_json(param_obj)
it return => {'word_counts': [{'value': 10, 'key': u'a'}, {'value': 20, 'key': u'b'}]} but i expect as: {'a': 10, 'b': 20}
The text was updated successfully, but these errors were encountered:
I test this repos. https://github.com/wayhome/thrift_json/tree/master/thrift_json it seems ok, to convert obj with map to json.
Sorry, something went wrong.
elif ttype == TType.MAP: (key_ttype, key_ttype_info, val_ttype, val_ttype_info) = ttype_info ret = dict([(self._convert(k, key_ttype, key_ttype_info), self._convert(v, val_ttype, val_ttype_info)) for (k, v) in val.items()])
def map_to_json(val, spec): res = dict() if isinstance(spec[0], int): key_type = spec[0] key_spec = None else: key_type, key_spec = spec[0] if isinstance(spec[1], int): value_type = spec[1] value_spec = None else: value_type, value_spec = spec[1] for k, v in val.items(): if json_value(key_type, k, key_spec): res[json_value(key_type, k, key_spec)] = json_value(value_type, v, value_spec) return res
@yexiaoya Try this function: #152 (comment)
No branches or pull requests
thrift
struct WordCloudParam {
1: optional map<string, i32> word_counts # {'a': 10, 'b': 20}
}
import thriftpy2.protocol.json as thrift_json
param_obj = WordCloudParam(word_counts={'a': 10, 'b': 20})
param_json = thrift_json.struct_to_json(param_obj)
it return => {'word_counts': [{'value': 10, 'key': u'a'}, {'value': 20, 'key': u'b'}]}
but i expect as: {'a': 10, 'b': 20}
The text was updated successfully, but these errors were encountered: