Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

python 字符串转json 出错

调用google翻译英文,返回的字符串数据无法转换为json。请问大神怎么取出数据。PS:只要中文。

str1 = '''[[["熊猫越来越熟悉互联网的发展。","Panda is familiar by more and more people as the development of Internet.",,,3],["现在人们可以看到互联网上的现场表演。","Now people can see the live show from the Internet.",,,3],["这些可爱的天使受到来自世界各地的粉丝的青睐。","These lovely angels are favored by the fans from all over the world.",,,3],["他们在日常生活中做什么让人大声笑起来。","What they do in the daily life makes people laugh out loudly.",,,3],["没有人能够抵挡这些天使的魅力。","No one can resist the charm from these angels.",,,3],["但是众所周知,熊猫正在死亡,因为他们不容易生出新的婴儿。","But it is known to all that panda is dying out, because it is not easy for them to get birth to the new babies.",,,3],["更重要的是,人们破坏了环境,使熊猫失去了家园。","What’s more, people damage the environment, which makes panda lose their home.",,,3],["我们可以做小事来保护他们。","We can do small things to protect them.",,,3],["当我们去动物园时,我们不应该扔掉垃圾,保持安静,不要打扰这些可爱的生物。","When we go to the zoo, we should not throw away the rubbish and keep quiet, in the purpose of not to disturb these lovely creature.",,,3],["我们爱熊猫,我们有责任保护他们不要死亡。","We love panda, it is our duty to protect them from dying out.",,,3],[,,"Xióngmāo yuè lái yuè shúxī hùliánwǎng de fǎ zhǎn. Xiànzài rénmen kěyǐ kàn dào hùliánwǎng shàng de xiànchǎng biǎoyǎn. Zhèxiē kě'ài de tiānshǐ shòudào láizì shìjiè gèdì de fěnsī de qīnglài. Tāmen zài rìcháng shēnghuó zhōng zuò shénme ràng rén dàshēng xiào qǐlái. Méiyǒu rén nénggòu dǐdǎng zhèxiē tiānshǐ de mèilì. Dànshì zhòngsuǒzhōuzhī, xióngmāo zhèngzài sǐwáng, yīnwèi tāmen bù róngyì shēngchū xīn de yīng'ér. Gèng zhòngyào de shì, rénmen pòhuàile huánjìng, shǐ xióngmāo shīqùle jiāyuán. Wǒmen kěyǐ zuò xiǎoshì lái bǎohù tāmen. Dāng wǒmen qù dòngwùyuán shí, wǒmen bù yìng gāi rēng diào lèsè, bǎochí ānjìng, bùyào dǎrǎo zhèxiē kě'ài de shēngwù. Wǒmen ài xióngmāo, wǒmen yǒu zérèn bǎohù tāmen bùyào sǐwáng."]],,"en",,,[["Panda is familiar by more and more people as the development of Internet.",,[["熊猫越来越熟悉互联网的发展。",0,true,false],["熊猫是越来越多的人随着互联网的发展熟悉。",0,true,false]],[[0,73]],"Panda is familiar by more and more people as the development of Internet.",0,0],["Now people can see the live show from the Internet.",,[["现在人们可以看到互联网上的现场表演。",0,true,false],["现在,人们可以从网上看到的现场表演。",0,true,false]],[[0,51]],"Now people can see the live show from the Internet.",0,0],["These lovely angels are favored by the fans from all over the world.",,[["这些可爱的天使受到来自世界各地的粉丝的青睐。",0,true,false],["这些可爱的天使是由球迷从世界各地的青睐。",0,true,false]],[[0,68]],"These lovely angels are favored by the fans from all over the world.",0,0],["What they do in the daily life makes people laugh out loudly.",,[["他们在日常生活中做什么让人大声笑起来。",0,true,false],["他们在日常生活中做些什么让人笑了一声。",0,true,false]],[[0,61]],"What they do in the daily life makes people laugh out loudly.",0,0],["No one can resist the charm from these angels.",,[["没有人能够抵挡这些天使的魅力。",0,true,false],["没有人能抵抗这些天使的魅力。",0,true,false]],[[0,46]],"No one can resist the charm from these angels.",0,0],["But it is known to all that panda is dying out, because it is not easy for them to get birth to the new babies.",,[["但是众所周知,熊猫正在死亡,因为他们不容易生出新的婴儿。",0,true,false],["但众所周知,大熊猫正在消亡,因为它是不容易的,他们得到孕育了新的婴儿。",0,true,false]],[[0,111]],"But it is known to all that panda is dying out, because it is not easy for them to get birth to the new babies.",0,0],["What’s more, people damage the environment, which makes panda lose their home.",,[["更重要的是,人们破坏了环境,使熊猫失去了家园。",0,true,false],["更重要的是,人们破坏环境,这使得熊猫失去了自己的家。",0,true,false]],[[0,78]],"What’s more, people damage the environment, which makes panda lose their home.",0,0],["We can do small things to protect them.",,[["我们可以做小事来保护他们。",0,true,false],["我们可以做的小东西来保护他们。",0,true,false]],[[0,39]],"We can do small things to protect them.",0,0],["When we go to the zoo, we should not throw away the rubbish and keep quiet, in the purpose of not to disturb these lovely creature.",,[["当我们去动物园时,我们不应该扔掉垃圾,保持安静,不要打扰这些可爱的生物。",0,true,false],["当我们去动物园,我们不应该扔掉的垃圾,保持安静,在不打扰这些可爱的动物的目的。",0,true,false]],[[0,131]],"When we go to the zoo, we should not throw away the rubbish and keep quiet, in the purpose of not to disturb these lovely creature.",0,0],["We love panda, it is our duty to protect them from dying out.",,[["我们爱熊猫,我们有责任保护他们不要死亡。",0,true,false],["我们爱熊猫,我们有责任保护他们免受灭绝。",0,true,false]],[[0,61]],"We love panda, it is our duty to protect them from dying out.",0,0]],0.99901491,,[["en"],,[0.99901491],["en"]]]'''

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
>>> import re
>>> import json
>>> ss=re.sub(r'([[,])(?=,)',r'1null',str1)
>>> j=json.loads(ss)
>>> for l in j[0]:
    if l[0] is None : break
    print(l[0])
    
##熊猫越来越熟悉互联网的发展。
##现在人们可以看到互联网上的现场表演。
##这些可爱的天使受到来自世界各地的粉丝的青睐。
##他们在日常生活中做什么让人大声笑起来。
##没有人能够抵挡这些天使的魅力。
##但是众所周知,熊猫正在死亡,因为他们不容易生出新的婴儿。
##更重要的是,人们破坏了环境,使熊猫失去了家园。
##我们可以做小事来保护他们。
##当我们去动物园时,我们不应该扔掉垃圾,保持安静,不要打扰这些可爱的生物。
##我们爱熊猫,我们有责任保护他们不要死亡。

>>> for l in j[5]:
    if isinstance(l,list):print(l[2][1][0])

    
##熊猫是越来越多的人随着互联网的发展熟悉。
##现在,人们可以从网上看到的现场表演。
##这些可爱的天使是由球迷从世界各地的青睐。
##他们在日常生活中做些什么让人笑了一声。
##没有人能抵抗这些天使的魅力。
##但众所周知,大熊猫正在消亡,因为它是不容易的,他们得到孕育了新的婴儿。
##更重要的是,人们破坏环境,这使得熊猫失去了自己的家。
##我们可以做的小东西来保护他们。
##当我们去动物园,我们不应该扔掉的垃圾,保持安静,在不打扰这些可爱的动物的目的。
##我们爱熊猫,我们有责任保护他们免受灭绝。

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...