javascript - 将严重字符串化的 json 转换为 json 对象
问题描述
我有一些从网络服务中提取的数据。这是字符串
(正文:'3886' MessageProperties [headers={},timestamp=null,messageId=null,userId=null,receivedUserId=null,appId=null,clusterId=null,type=null,correlationId=null,correlationIdString=null,replyTo =null,contentType=application/x-java-serialized-object,contentEncoding=null,contentLength=0,deliveryMode=null,receivedDeliveryMode=PERSISTENT,expiration=null,priority=0,redelivered=false,receivedExchange=,receivedRoutingKey=bottomlesspit, receivedDelay=null,deliveryTag=62,messageCount=0,consumerTag=amq.ctag-sCwfLaMEqWp2GkFwFrY1yg,consumerQueue=bottomlesspit])
它看起来像 json,但键值对几乎Body
没问题,但最重要的键与字符串所告诉的其他键不同。
我需要读取的值Body
并能够获得这样的值
console.log(d.body);
//This above outputs the string as shown
obj = eval('{' + d.body + '}');
console.log(obj);
var match = "Body";
var val = obj.find( function(item) { return item.key == match } );
console.log(val);
我如何读取密钥的值Body
?
解决方案
使用这个正则表达式而不是 match Body
:
\bBody:'(\d*)'
这将捕获第 1 组中的 Body 编号。
推荐阅读
- git - 合并会删除未推送的提交吗?
- c# - 为什么 RichTextBox 中没有插入图像?
- python - 设置代理让keras/tensorflow下载需要的json
- openlayers - OpenLayers v 5.3.0 - 找回归因行为
- regex - 具有不同 t(unknown) 字符串匹配的正则表达式
- c++ - 在 C++ 中限制头文件的目的是什么
- android - 打开多个文件描述符到 /dev/ion
- windows - 如何获取在 Powershell 中使用 RSS 的特定 NIC 的 NUMA 差异
- kotlin - 有没有解决“无法访问”的方法
':它在 XYZ 中是私有的吗? - postgresql - postgresql:创建整数乘法运算符的文本