用反斜杠解析json对象并将其添加回数据json

时间:2018-05-23 05:07:50

标签: javascript angularjs json parsing

只是想知道,在下面的JSON中,是否可以解析单个对象调用'数据',删除反斜杠,分隔单个对象中的每个键值对,以及然后将其追加回原始的JSON数据。

此:

{
  "Timestamp": "2018-05-14T20:02:57.000Z",
  "Data": "{\"UserId\":\"00529000001jD4uAAE\",\"CardElement\":\"Total Due\",\"EntityLabel\":\"Total Due\",\"EntityName\":\"Contract Account\",\"TrackingEvent\":\"Field\",\"TrackingService\":\"VCards\"}",
  "CustomerInteractionId": "a1629000000VQgvAAG",
  "Vlocity Tracking Entry Name": "Field"
}

变成这样:

 {
  "Timestamp": "2018-05-14T20:02:57.124Z",
  "CustomerInteractionId": "a1629000000VQgvAAG",
  "Vlocity Tracking Entry Name": "Field",
  "UserId": "00529000001jD4uAAE",
  "CardElement": "Total Due",
  "EntityLabel": "Contract Account",
  "TrackingEvent": "Field",
  "TrackingService": "VCards"
}

将一些问题分解为自己的键值对并将其附加回JSON。可以在JSAngularJS

2 个答案:

答案 0 :(得分:1)

firewalls: user: pattern: ^/api/auth stateless: true anonymous: true json_login: check_path: /api/auth/login_check success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure require_previous_session: false api: pattern: ^/api stateless: true guard: authenticators: - lexik_jwt_authentication.jwt_token_authenticator access_control: - { path: ^/api/auth, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/api, roles: IS_AUTHENTICATED_FULLY } 是JSON中的字符串。您可以有选择地解析字符串,然后使用已解析的Data和原始对象创建一个新对象。然后从新对象中删除Data

Data

答案 1 :(得分:1)



   

var datas = {
  "Timestamp": "2018-05-14T20:02:57.000Z",
  "Data": "{\"UserId\":\"00529000001jD4uAAE\",\"CardElement\":\"Total Due\",\"EntityLabel\":\"Total Due\",\"EntityName\":\"Contract Account\",\"TrackingEvent\":\"Field\",\"TrackingService\":\"VCards\"}",
  "CustomerInteractionId": "a1629000000VQgvAAG",
  "Vlocity Tracking Entry Name": "Field"
};

datas = Object.assign({}, datas, JSON.parse(datas.Data));
delete datas.Data;
console.log(datas);