我有一个protobuf在Python中反序列化的对象.当我打印对象时,它看起来像一个python对象,但是当我尝试将其转换为json我有各种各样的问题时.
例如,如果我使用json.dumps()我得到的对象(从protoc生成的代码)不包含_ dict _错误.
如果我使用jsonpickle,我会得到UnicodeDecodeError: 'utf8' codec can't decode byte 0x9d in position 97: invalid start byte.
下面的测试代码使用jsonpickle上面显示的错误.
if len(sys.argv) < 2:
print ("Error: missing ser file")
sys.exit()
else :
fileLocation = sys.argv[1]
org = BuildOrgObject(fileLocation)
org = org.Deserialize()
#print (org)
jsonObj = jsonpickle.encode(org)
print (jsonObj)
Run Code Online (Sandbox Code Playgroud) 我正在尝试更多地设计模式,我正在构建一个快速测试,以帮助我进一步了解单例模式.然而,我在.net中遇到了一个让我感到困惑的错误,是什么让它更奇怪我无法复制错误,这只会增加我的困惑.下面的代码不是世界上最好的代码,但我随机测试的东西可以帮助我更深入地理解.
class Program
{
static void Main(string[] args)
{
Thread t1 = new Thread(new ThreadStart(run1));
Thread t2 = new Thread(new ThreadStart(run2));
t1.Priority = ThreadPriority.Lowest;
t1.Start();
t2.Priority = ThreadPriority.Lowest;
t2.Start();
Console.ReadLine();
}
public static void run1()
{
Console.WriteLine("im in run1 \n");
TestSingleton._instance.PopulateCrudItemsProcess();
Thread.Sleep(1000);
Console.WriteLine(TestSingleton._instance.GetStrValue("first", 1000));
}
public static void run2()
{
Console.WriteLine("im in run2 \n");
TestSingleton._instance.PopulateCrudItemsProcess();
Console.WriteLine(TestSingleton._instance.GetStrValue("second", 500));
}
}
sealed class TestSingleton
{
private TestSingleton() { }
public static readonly TestSingleton _instance = new TestSingleton();
public string GetStrValue(string str, int …Run Code Online (Sandbox Code Playgroud)