gpt4 book ai didi

java - 无法将字符串转换为长字符串

转载 作者:行者123 更新时间:2023-12-01 18:26:46 25 4
gpt4 key购买 nike

所以,这是我的代码..

 HashMap<Long, Long> trackCount = new HashMap<Long, Long>(); 
for (Text value: values)
{
String[] chunks = value.toString().split(DELIMITER);
Long trackId = Long.parseLong(chunks[0]); // see i convert it to Long
Long frequency = Long.parseLong(chunks[1]);
Long curFreq = 0l;
if(trackCount.containsKey(trackId)){
curFreq = trackCount.get(trackId);
}
trackCount.put(trackId, curFreq + frequency); // key is trackId which is long..
}
trackFrequency.put("track_id", key);
trackFrequency.put("track_counts", trackCount);
context.write(NullWritable.get(), new Text(trackFrequency.toJSONString()));

这本质上是一个hadoop代码..但我看到的最终输出是

     {"track_counts":{"2":52,"3":2,"7":32},"track_id":1}

现在为什么 track_counts 中的键是关于字符串的。我以为我将它们转换为 Long?

最佳答案

The name in JSON name-value pairs can only be a String.无论您的序列化程序是什么,它都会在将映射键写入 JSON 之前将其转换为 String

关于java - 无法将字符串转换为长字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25858782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com