我试图转换这个JSON:
else if (id == R.id.action_share) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBodyText = "Check it out this product";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(sharingIntent, "Shearing Option"));
return true;
}
到{
"labels": ["time", "free", "used", "cached", "buffers"],
"data": [
[1478635365, 26.91797, 460.9844, 479.3906, 5.80859]
]
}
你能帮助我吗?
答案 0 :(得分:1)
以下是使用var
创建zip()
dict的 dict comprehension 表达式:
>>> my_json = { "labels": ["time", "free", "used", "cached", "buffers"], "data": [ [ 1478635365, 26.91797, 460.9844, 479.3906, 5.80859] ] }
>>> var = {k: v for k, v in zip(my_json["labels"], my_json["data"][0])}
现在您可以访问var
dict中的值:
>>> var["time"]
1478635365
>>> var["free"]
26.91797