Javascript 从JSON字符串中提取图像

Javascript 从JSON字符串中提取图像,javascript,mathml,Javascript,Mathml,任务:将其视为字符串,将字符串中的所有图像复制到您选择的任何数据库中,并使用新URL重建字符串 {"_items": [{"_id": "5f5b6acab4175c979b8cb5af", "owning_partner_id": 10304, "type": "Question", "subtype": "Subjective", &

任务:将其视为字符串,将字符串中的所有图像复制到您选择的任何数据库中,并使用新URL重建字符串

{"_items": [{"_id": "5f5b6acab4175c979b8cb5af", "owning_partner_id": 10304, "type": "Question", "subtype": "Subjective", "modifier": "Judgemental", "status": "Draft", "author_id": 4542, "assigned_to": 4542, "content": {"question_details": {"en": {"answers": [{"body": "", "is_correct": true, "explanation": ".", "code": "a"}], "question_txt": "

In the figure, a rectangular block is gradually pushed face down into a liquid. The block has height <math xmlns="http://www.w3.org/1998/Math/MathML">d; on the bottom and top the face area is <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="normal">A=8.00 cm2. In the figure, gives the apparent weight <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="normal">Wapp of the block as a function of the depth <math xmlns="http://www.w3.org/1998/Math/MathML">h of its lower face. The scale on the vertical axis is set by <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="normal">W<mi mathvariant="normal">s=0.20 <mi mathvariant="normal">N. What is the density of the liquid ?

\n\n
<img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.lusIzGK6zcFw1rxBK38KHQHaE8%26pid%3DApi&f=1" style="width: 245px; height: 150px;" />  <img src="https://static.theceomagazine.net/wp-content/uploads/2018/10/15093202/elon-musk-1100x733.jpg" style="width: 245px; height: 197px;" /> 

\n"}}, "book_toc": [], "question_meta_tags": [{"difficulty_level": "", "primary_concept": "", "ideal_time": "", "secondary_concept": [], "learning_maps": [], "learning_maps_data": []}]}, "superseded_by": null, "language": "en", "is_atg_ready": 0, "created_by": 4542, "updated_by": 4542, "is_prof_approved": 0, "content_schema_version": 1, "version": 1, "_updated": "Fri, 11 Sep 2020 12:17:14 GMT", "_created": "Fri, 11 Sep 2020 12:17:14 GMT", "_version": 1, "tenant_id": 1, "title": "
In the figure, a rectangular block is gradually pushed face down into a liquid. The block has height <math xmlns="http://www.w3.org/1998/Math/MathML">d; on the bottom and top the face area is <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="normal">A=8.00 cm2. In the figure, gives the apparent weight <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="normal">Wapp of the block as a function of the depth <math xmlns="http://www.w3.org/1998/Math/MathML">h of its lower face. The scale on the vertical axis is set by <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="normal">W<mi mathvariant="normal">s=0.20 <mi mathvariant="normal">N. What is the density of the liquid ?

\n\n
<img src="https://www.teslarati.com/wp-content/uploads/2018/08/elon-musk-1-AP.jpg" style="width: 245px; height: 150px;" />  <img src="https://www.teslarati.com/wp-content/uploads/2018/08/elon-musk-1-AP.jpg" style="width: 245px; height: 197px;" /> 

\n", "id": 6126381, "question_code": "EM6126381-en", "uuid": "d00dfd63-082e-4062-8f1f-e37e7c9f0829", "created_at": "Fri, 11 Sep 2020 12:17:14 GMT", "updated_at": "Fri, 11 Sep 2020 12:17:14 GMT", "_etag": "3027df270a05e67d65b254d9b134bab952cbcd68", "_links": {"self": {"title": "learning_objects", "href": "learning_objects/5f5b6acab4175c979b8cb5af"}}, "_latest_version": 1, "user_name": "reshma awale"}], "_links": {"parent": {"title": "home", "href": "/"}, "self": {"title": "learning_objects", "href": "learning_objects?where={"type":"Question","$or":[{"id":{"$in":[6126381]}},{"question_code":{"$in":[]}}]}&sort=id&embed=true"}}, "_meta": {"page": 1, "max_results": 25, "total": 1}}
{{u items:[{{u id:“5f5b6acab4175c979b8cb5af”,“拥有配偶的id:”10304,“类型”:“问题”,“子类型”:“主观”,“修饰语”:“判断”,“状态”:“草稿”,“作者id”:4542,“分配给”:4542,“内容”:{“问题详细信息”:{”en:{“答案”:[{“正文”:“正确”:true,“解释”:“代码”:“a”;“问题文本”:"
在图中,一个矩形试块面朝下逐渐推入液体中。试块的高度为d;在底部和顶部,试块的表面面积为a=8.00 cm2。在图中,给出了试块的表观重量Wapp,作为其下表面深度h的函数。垂直轴上的刻度设置为Ws=0.20 N。液体的密度是多少?
\n\n
\n“}”,book_toc:[],“question_meta_tags:“{”难度等级“,“primary_concept:”,“ideal_time:“,”secondary_concept:“,”learning_maps:“[]”,learning_maps_data:“[]”,被“:null”取代,“language:“en”,“is_atg_ready:”0,“创建人”:4542,“更新人”:4542,“是否获得教授批准”:0,“内容模式版本”:1,“版本”:1,“更新版”:“2020年9月11日星期五12:17:14 GMT”,“创建版”:“2020年9月11日星期五12:17:14 GMT”,“版本”:1,“租户id”:1,“标题”:
在图中,一个矩形试块面朝下逐渐推入液体中。试块的高度为d;在底部和顶部,试块的表面面积为a=8.00 cm2。在图中,给出了试块的表观重量Wapp,作为其下表面深度h的函数。垂直轴上的刻度设置为Ws=0.20 N。液体的密度是多少?
\n\n
\n,“id”:6126381,“问题代码”:“EM6126381 en”,“uuid”:“d00dfd63-082e-4062-8f1f-e37e7c9f0829”,“创建时间”:“Fri,2020年9月11日12:17:14 GMT”,“更新时间”:“Fri,2020年9月11日12:17:14 GMT”,“UETag”:“3027df270a05e67d65b254d9b134bab952cbcd68”,“U链接”:{“self:{”title:“learning href:“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”,“{u最新版本”:1,“用户名”:“reshma awale”}],“{u链接”:{“家长”:{“标题”:“主页”,“href”:“//”},“自我”:{“标题”:“学习对象”,“href”:“学习对象”?where={“类型”:“问题”,“$或”:[{“id”:“{”$in:[6126381]},{“问题代码”:{“$in:[]}}”}&sort=id&embed=true”:{

也许你是这个意思

PS:由于嵌套MathML中的\n和双引号,您的JSON(如果应该是这样)无效

let string=`{{u items:[{{u id:“5f5b6acab4175c979b8cb5af”,“拥有合作伙伴的id:”10304,“类型:”:“问题”,“子类型:”:“主观”,“修改者:”:“判断”,“状态:”:“草稿”,“作者id:”4542,“分配给”:4542,“内容:{“问题详细信息:”{“en:{“答案:”:[{“正文:”,“是否正确:”:”真,“解释:”,“代码:”:“a”,“问题”:
在图中,一个矩形试块面朝下逐渐推入液体中。试块的高度为d;在底部和顶部,试块的表面面积为a=8.00 cm2。在图中,给出了试块的表观重量Wapp,作为其下表面深度h的函数。垂直轴上的刻度设置为Ws=0.20 N。液体的密度是多少?
\n\n
\n“}”,book_toc:[],“question_meta_tags:“{”难度等级“,“primary_concept:”,“ideal_time:“,”secondary_concept:“,”learning_maps:“[]”,learning_maps_data:“[]”,被“:null”取代,“language:“en”,“is_atg_ready:”0,“创建人”:4542,“更新人”:4542,“是否获得教授批准”:0,“内容模式版本”:1,“版本”:1,“更新版”:“2020年9月11日星期五12:17:14 GMT”,“创建版”:“2020年9月11日星期五12:17:14 GMT”,“版本”:1,“租户id”:1,“标题”:
在图中,一个矩形试块面朝下逐渐推入液体中。试块的高度为d;在底部和顶部,试块的表面面积为a=8.00 cm2。在图中,给出了试块的表观重量Wapp,作为其下表面深度h的函数。垂直轴上的刻度设置为Ws=0.20 N。液体的密度是多少?
\n\n
\n,“id”:6126381,“问题代码”:“EM6126381 en”,“uuid”:“d00dfd63-082e-4062-8f1f-e37e7c9f0829”,“创建时间”:“Fri,2020年9月11日12:17:14 GMT”,“更新时间”:“Fri,2020年9月11日12:17:14 GMT”,“UETag”:“3027df270a05e67d65b254d9b134bab952cbcd68”,“U链接”:{“self:{”title:“learning href:“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”;“learning”,“{u最新版本”:1,“用户名”:“reshma awale”}],“{u链接”:{“家长”:{“标题”:“主页”,“href”:“//”},“自我”:{“标题”:“学习对象”,“href”:“学习对象”?where={“类型”:“问题”,“$或”:[{“id”:“{”$in:[6126381]},{“问题代码”:{“$in:[]}}”}&sort=id&embed=true”:{`
const images=string.match(/]+)“/g)
const div=document.createElement(“div”);
div.innerHTML+=images.join(“
”);//您可以在内存中使用div const sources=[…div.queryselectoral(“img”)].map(img=>img.src) console.log(源代码) sources.forEach(src=>{ 常量url=新url(src) url.hostname=“yourhost.com”; string=string.split(src.join)(url.href); })
console.log(string)
欢迎使用Stack Overflow!请访问,查看和。进行一些研究,搜索与此相关的主题;如果遇到问题,请发布您的尝试,并使用
[]记录输入和预期输出
snippet editor。您的问题是什么?我试图为您提出一个正确的问题。请添加相关信息和您的尝试!顺便说一下,您的字符串不是有效的JSON