av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python 字符串轉(zhuǎn)json 出錯(cuò)

瀏覽:88日期:2022-08-11 17:30:53

問(wèn)題描述

調(diào)用google翻譯英文,返回的字符串?dāng)?shù)據(jù)無(wú)法轉(zhuǎn)換為json。請(qǐng)問(wèn)大神怎么取出數(shù)據(jù)。PS:只要中文。

str1 = ’’’[[['熊貓?jiān)絹?lái)越熟悉互聯(lián)網(wǎng)的發(fā)展。','Panda is familiar by more and more people as the development of Internet.',,,3],['現(xiàn)在人們可以看到互聯(lián)網(wǎng)上的現(xiàn)場(chǎng)表演。','Now people can see the live show from the Internet.',,,3],['這些可愛(ài)的天使受到來(lái)自世界各地的粉絲的青睞。','These lovely angels are favored by the fans from all over the world.',,,3],['他們?cè)谌粘I钪凶鍪裁醋屓舜舐曅ζ饋?lái)。','What they do in the daily life makes people laugh out loudly.',,,3],['沒(méi)有人能夠抵擋這些天使的魅力。','No one can resist the charm from these angels.',,,3],['但是眾所周知,熊貓正在死亡,因?yàn)樗麄儾蝗菀咨鲂碌膵雰骸?,'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],['更重要的是,人們破壞了環(huán)境,使熊貓失去了家園。','What’s more, people damage the environment, which makes panda lose their home.',,,3],['我們可以做小事來(lái)保護(hù)他們。','We can do small things to protect them.',,,3],['當(dāng)我們?nèi)?dòng)物園時(shí),我們不應(yīng)該扔掉垃圾,保持安靜,不要打擾這些可愛(ài)的生物。','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],['我們愛(ài)熊貓,我們有責(zé)任保護(hù)他們不要死亡。','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.',,[['熊貓?jiān)絹?lái)越熟悉互聯(lián)網(wǎng)的發(fā)展。',0,true,false],['熊貓是越來(lái)越多的人隨著互聯(lián)網(wǎng)的發(fā)展熟悉。',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.',,[['現(xiàn)在人們可以看到互聯(lián)網(wǎng)上的現(xiàn)場(chǎng)表演。',0,true,false],['現(xiàn)在,人們可以從網(wǎng)上看到的現(xiàn)場(chǎng)表演。',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.',,[['這些可愛(ài)的天使受到來(lái)自世界各地的粉絲的青睞。',0,true,false],['這些可愛(ài)的天使是由球迷從世界各地的青睞。',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.',,[['他們?cè)谌粘I钪凶鍪裁醋屓舜舐曅ζ饋?lái)。',0,true,false],['他們?cè)谌粘I钪凶鲂┦裁醋屓诵α艘宦暋?,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.',,[['沒(méi)有人能夠抵擋這些天使的魅力。',0,true,false],['沒(méi)有人能抵抗這些天使的魅力。',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.',,[['但是眾所周知,熊貓正在死亡,因?yàn)樗麄儾蝗菀咨鲂碌膵雰骸?,0,true,false],['但眾所周知,大熊貓正在消亡,因?yàn)樗遣蝗菀椎模麄兊玫皆杏诵碌膵雰骸?,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.',,[['更重要的是,人們破壞了環(huán)境,使熊貓失去了家園。',0,true,false],['更重要的是,人們破壞環(huán)境,這使得熊貓失去了自己的家。',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.',,[['我們可以做小事來(lái)保護(hù)他們。',0,true,false],['我們可以做的小東西來(lái)保護(hù)他們。',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.',,[['當(dāng)我們?nèi)?dòng)物園時(shí),我們不應(yīng)該扔掉垃圾,保持安靜,不要打擾這些可愛(ài)的生物。',0,true,false],['當(dāng)我們?nèi)?dòng)物園,我們不應(yīng)該扔掉的垃圾,保持安靜,在不打擾這些可愛(ài)的動(dòng)物的目的。',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.',,[['我們愛(ài)熊貓,我們有責(zé)任保護(hù)他們不要死亡。',0,true,false],['我們愛(ài)熊貓,我們有責(zé)任保護(hù)他們免受滅絕。',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']]]’’’

問(wèn)題解答

回答1:

>>> 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]) ##熊貓?jiān)絹?lái)越熟悉互聯(lián)網(wǎng)的發(fā)展。##現(xiàn)在人們可以看到互聯(lián)網(wǎng)上的現(xiàn)場(chǎng)表演。##這些可愛(ài)的天使受到來(lái)自世界各地的粉絲的青睞。##他們?cè)谌粘I钪凶鍪裁醋屓舜舐曅ζ饋?lái)。##沒(méi)有人能夠抵擋這些天使的魅力。##但是眾所周知,熊貓正在死亡,因?yàn)樗麄儾蝗菀咨鲂碌膵雰骸?#更重要的是,人們破壞了環(huán)境,使熊貓失去了家園。##我們可以做小事來(lái)保護(hù)他們。##當(dāng)我們?nèi)?dòng)物園時(shí),我們不應(yīng)該扔掉垃圾,保持安靜,不要打擾這些可愛(ài)的生物。##我們愛(ài)熊貓,我們有責(zé)任保護(hù)他們不要死亡。>>> for l in j[5]: if isinstance(l,list):print(l[2][1][0]) ##熊貓是越來(lái)越多的人隨著互聯(lián)網(wǎng)的發(fā)展熟悉。##現(xiàn)在,人們可以從網(wǎng)上看到的現(xiàn)場(chǎng)表演。##這些可愛(ài)的天使是由球迷從世界各地的青睞。##他們?cè)谌粘I钪凶鲂┦裁醋屓诵α艘宦暋?#沒(méi)有人能抵抗這些天使的魅力。##但眾所周知,大熊貓正在消亡,因?yàn)樗遣蝗菀椎模麄兊玫皆杏诵碌膵雰骸?#更重要的是,人們破壞環(huán)境,這使得熊貓失去了自己的家。##我們可以做的小東西來(lái)保護(hù)他們。##當(dāng)我們?nèi)?dòng)物園,我們不應(yīng)該扔掉的垃圾,保持安靜,在不打擾這些可愛(ài)的動(dòng)物的目的。##我們愛(ài)熊貓,我們有責(zé)任保護(hù)他們免受滅絕。回答2:

這不是 JSON。

我解析過(guò)這鬼東西:

# vim:fileencoding=utf-8from pyparsing import ( empty, Word, Forward, Suppress, delimitedList, nums, Combine, Regex, ZeroOrMore, hexnums, CharsNotIn, Literal,)escape_map = { ’b’: ’b’, ’f’: ’f’, ’n’: ’n’, ’r’: ’r’, ’t’: ’t’,}def unescapeChar(c): if c in escape_map: return escape_map[c] else: return cescapedChar = ’’ + Regex(’.’)escapedChar.setParseAction(lambda toks: unescapeChar(toks[1]))unicodeChar = (r’u’ + Word(hexnums, exact=4)).setParseAction(lambda toks: chr(int(toks[1], 16)))jString = ’'’ + Combine(ZeroOrMore(unicodeChar | escapedChar | CharsNotIn(’'’))) + ’'’jString.setParseAction(lambda toks: toks[1])jNull = empty(’null’).setParseAction(lambda: [None])jTrue = Literal(’true’).setParseAction(lambda: [True])jFalse = Literal(’false’).setParseAction(lambda: [False])integer = Word(’-’+nums, nums).setParseAction(lambda toks: [int(toks[0])])jAtom = jString | integer | jTrue | jFalse | jNulljArray = Forward()jArray << Suppress(’[’) + delimitedList(jArray | jAtom) + Suppress(’]’)jArray.setParseAction(lambda toks: [[]] if len(toks) == 1 and toks[0] is None else [toks])if __name__ == ’__main__’: test = ’[true,false,,]’ out = jArray.parseString(test).asList()[0] print(out) test = ’[,'ja',[['沙',[4],false,false,1000,0,1,0],]]’ out = jArray.parseString(test).asList()[0] print(out) test = r’’’[[['鬼','ゴースト','Guǐ','Gō'suto']],,'ja',,[['鬼',[4],0,0,1000,-20, 1,0]],[['ゴースト',4,[['鬼',1000,0,0],['幽靈',0,0,0],['鬼魂',0,0,0],['幽魂', 0,0,0],['靈魂',0,0,0]],[[0,4]],'ゴースト']],,,[['ja']],1] ’’’ out = jArray.parseString(test).asList()[0] print(out) out = jArray.parseString(’[]’).asList()[0] print(out) out = jArray.parseString(’[1,2,,4,[],]’).asList()[0] print(out) out = jArray.parseString(’[[,]]’).asList()[0] print(out) out = jString.parseString(r’'this is a u003e test't, hehe'’)[0] print(out)回答3:

你的json串里莫名其妙怎么這么多逗號(hào),連續(xù)的逗號(hào)導(dǎo)致json解析失敗

回答4:

import reres = re.findall(r'([u4E00-u9FA5]+)',str1)print(res)

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 日韩免费在线 | 久久美女网 | 精品久久久久久久久久 | 日日淫 | 99精品在线观看 | 国产精品久久毛片av大全日韩 | 亚洲伊人a | 久久久无码精品亚洲日韩按摩 | 自拍偷拍av | 国产在线小视频 | 久久免费看 | 天天欧美 | 久久久久国色av免费观看性色 | 久久久久国产精品一区二区 | 国产一区久久 | 香蕉大人久久国产成人av | 成人在线视频免费观看 | 在线成人免费视频 | 国产精品久久久久一区二区三区 | 亚洲性人人天天夜夜摸 | 日韩国产在线观看 | 免费视频一区 | 羞羞视频在线网站观看 | 在线观看av网站 | 国产一二三区免费视频 | 中文字幕一二三 | 色婷婷久久久亚洲一区二区三区 | 亚洲入口| 国产超碰人人爽人人做人人爱 | 天堂一区二区三区 | аⅴ资源新版在线天堂 | 亚洲视频免费 | 欧美成人h版在线观看 | 亚洲精品久久久一区二区三区 | 男女羞羞视频在线看 | 国产精品一区二区三区在线播放 | 日日天天 | 国产在线一区观看 | 国产免费一区二区 | 日本久久www成人免 成人久久久久 | 成人区精品|