这是我的JSON请求,我想从DataWeave转换中的JSON有效负载中删除<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyANdsvrNpO6CDr_-Y&callback=initMap"></script>
<script language="javascript" type="text/javascript">
var map;
var geocoder;
function InitializeMap() {
var latlng = new google.maps.LatLng(-29.833959630595874, 30.35492856055498);
var myOptions =
{
zoom: 9,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
}
function FindLocaiton() {
geocoder = new google.maps.Geocoder();
InitializeMap();
var address = document.getElementById("addressinput").value;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function Button1_onclick() {
FindLocaiton();
}
window.onload = InitializeMap;
</script>
字段。
我该怎么做?
dcsId
答案 0 :(得分:4)
为避免映射有效负载中的其他字段,您可以尝试此操作 -
%dw 1.0
%output application/json
---
(payload - 'details') ++ (payload.details - 'dcsId')
它首先获取有效负载中的所有内容,但不包括详细信息,然后通过排除dcsId来添加详细信息。
HTH!
答案 1 :(得分:2)
试试这个
%dw 1.0
%output application/json
---
{
status : payload.status,
statusCode : payload.status,
statusDescription : payload.statusDescription,
details : payload.details - 'dcsId'
}
希望这有帮助。
答案 2 :(得分:0)
这是只删除dcsId的表达式
NSPersistentStoreCoordinator
答案 3 :(得分:0)
尝试一下。
%dw 1.0
(有效负载-“详细信息”) ++ 详细信息:(payload.details-'dcsId')
答案 4 :(得分:0)
脚本
%dw 2.0
output application/json
---
(payload - 'details') ++ {details: payload.details - 'dcsId'}
输出
{
"status": "ok",
"statusCode": "11011",
"statusDescription": "Service: Get Profile ; Market: US ; Locale:en-US ; SourceId:DCS; ApiUid: 644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b; Description: The get profile call was successful.",
"details": {
"marketCode": "US",
"languageCode": "en",
"profile": {
"base": {
"username": "abc",
"firstName": "xc",
"middleName": "test",
"lastName": "123",
"shortName": "xc",
"displayName": "D",
"suffix": "T",
"prefix": "E"
}
}
}
}
答案 5 :(得分:0)
这是一个递归函数,用于从任何级别的 json 有效负载中删除键
%dw 2.0
output application/json
var data = {
"status": "ok",
"statusCode": "11011",
"statusDescription": "Service: Get Profile ; Market: US ; Locale:en-US ; SourceId:DCS; ApiUid: 644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b; Description: The get profile call was successful.",
"details": {
"dcsId": "rfggrg",
"marketCode": "US",
"languageCode": "en",
"profile": {
"base": {
"username": "abc",
"firstName": "xc",
"middleName": "test",
"lastName": "123",
"shortName": "xc",
"displayName": "D",
"suffix": "T",
"prefix": "E"
}
}
}
}
fun removeKey(val, keyToRemove) = val match {
case is Array -> $ map ((v) -> removeKey(v, keyToRemove))
case is Object -> ($ - keyToRemove) mapObject ((value, key, index) -> {(key): removeKey(value,keyToRemove)})
else -> $
}
---
removeKey(data,"dcsId")