如何使用python将带有unicode的dict转换为中文字符

时间:2017-05-10 15:53:21

标签: python json csv unicode

我在dict结构中有一些数据,比如

#include "stdafx.h"
#include <iostream>
#include <thread>
#include <ctime>
#include <vector>
using namespace std;

void shellSort(vector <vector<int>>& wp, int k)
 {
    int n = wp[k].size();
    for (int gap = n / 2; gap > 0; gap /= 2)
     {

       for (int i = gap; i < n; i++)
        {
           int temp = wp[k][i];
           int j;
           for (j = i; j >= gap && wp[k][j - gap] > temp; j -= gap)
               wp[k][j] = wp[k][j - gap];
           wp[k][j] = temp;
        }
      }
 }

  int main()
 {
    int N, thN, i;
    cout << "\nEnter the length of array: ";
    cin >> N;
    cout << "\nEnter the amount of threads: ";
    cin >> thN;
    int* A = new int[N];
    for (i = 0; i < N; i++)
        A[i] = rand() % 100;

    thread* t = new thread[thN];

    vector<vector<int> > wp(thN, vector<int>());

    int start = 0;
    for (i = 0; i < thN; i++){
        for (int j = start; j < start + N / thN; j++){
            wp[i].push_back(A[j]);
        }
        start += N / thN;
    }

    double endTime, startTime;
    startTime = clock();

    for (i = 0; i < thN; i++)
        t[i] = thread(shellSort,wp,i);

    for (i = 0; i < thN; i++)
        t[i].join();

    endTime = clock();

    cout << "Runtime of shell sort: " << (endTime - startTime) / 1000 << endl;// time in miliseconds
    system("pause");
}

这只是其中的一部分。我想解析数据并获得我想要的特定部分。但是数据采用unicode格式,我想知道如何将dict结构中的unicode值转换为中文格式。

1 个答案:

答案 0 :(得分:2)

没有&#39;中文格式&#39;。当您打印字典时,字符串将显示为一系列unicode代码点(因为unicode.__repr__返回的内容)。

它已经是中文文本了。

print yourdictionary['content']

将显示中文字符。我无法粘贴输出,因为当我复制粘贴它时,网站认为它是垃圾邮件。