Estoy tratando de leer partes del siguiente JSON en las hojas de Google, parece que hay matrices anidadas que tengo dificultades para insertar en una celda ... JSON principal
{
"lineItems": [
{
"name": "advertisers/1558261/lineItems/12317016",
"advertiserId": "1238261",
"campaignId": "1233305",
"insertionOrderId": "13016372",
"lineItemId": "12317016",
"displayName": "All | Routes| All Users | ABC | ABC-LI1",
"lineItemType": "LINE_ITEM_TYPE_DISPLAY_DEFAULT",
"entityStatus": "ENTITY_STATUS_ACTIVE",
"updateTime": "2020-04-15T12:51:42.929Z",
"partnerCosts": [
{
"costType": "PARTNER_COST_TYPE_THIRD_PARTY_AD_SERVER",
"feeType": "PARTNER_COST_FEE_TYPE_CPM_FEE",
"feeAmount": "1000000",
"invoiceType": "PARTNER_COST_INVOICE_TYPE_PARTNER"
},
{
"costType": "PARTNER_COST_TYPE_DOUBLE_VERIFY_PREBID",
"feeType": "PARTNER_COST_FEE_TYPE_CPM_FEE",
"feeAmount": "0",
"invoiceType": "PARTNER_COST_INVOICE_TYPE_DV360"
},
{
"costType": "PARTNER_COST_TYPE_DV360_FEE",
"feeType": "PARTNER_COST_FEE_TYPE_MEDIA_FEE",
"feePercentageMillis": "0",
"invoiceType": "PARTNER_COST_INVOICE_TYPE_DV360"
},
{
"costType": "PARTNER_COST_TYPE_DEFAULT",
"feeType": "PARTNER_COST_FEE_TYPE_MEDIA_FEE",
"feePercentageMillis": "0",
"invoiceType": "PARTNER_COST_INVOICE_TYPE_PARTNER"
}
],
"flight": {
"flightDateType": "LINE_ITEM_FLIGHT_DATE_TYPE_CUSTOM",
"dateRange": {
"startDate": {
"year": 2020,
"month": 4,
"day": 15
},
"endDate": {
"year": 2020,
"month": 4,
"day": 30
}
}
},
"budget": {
"budgetAllocationType": "LINE_ITEM_BUDGET_ALLOCATION_TYPE_UNLIMITED",
"budgetUnit": "BUDGET_UNIT_CURRENCY"
},
"pacing": {
"pacingPeriod": "PACING_PERIOD_DAILY",
"pacingType": "PACING_TYPE_EVEN",
"dailyMaxMicros": "40100000"
},
"frequencyCap": {
"timeUnit": "TIME_UNIT_DAYS",
"timeUnitCount": 1,
"maxImpressions": 5
},
"partnerRevenueModel": {
"markupType": "PARTNER_REVENUE_MODEL_MARKUP_TYPE_TOTAL_MEDIA_COST_MARKUP"
},
"conversionCounting": {
"postViewCountPercentageMillis": "100000",
"floodlightActivityConfigs": [
{
"1fI": "7517101",
"3PCdays": 30,
"2PVdays": 30
},
{
"1fI": "7541802",
"3PCdays": 30,
"2PVdays": 30
},
{
"1fI": "7552803",
"3PCdays": 30,
"2PVdays": 30
},
{
"1fI": "7517104",
"3PCdays": 30,
"2PVdays": 30
}
]
},
"bidStrategy": {
"fixedBid": {
"bidAmountMicros": "3610000"
}
},
"integrationDetails": {}
},
{
"name": "advertisers/1558261/lineItems/12317017",
"advertiserId": "1238261",
"campaignId": "1233305",
"insertionOrderId": "13016372",
"lineItemId": "12317017",
"displayName": "All | Routes| All Users | ABC | ABC-LI2",
"lineItemType": "LINE_ITEM_TYPE_DISPLAY_DEFAULT",
"entityStatus": "ENTITY_STATUS_ACTIVE",
"updateTime": "2020-04-01T16:06:19.831Z",
"partnerCosts": [
{
"costType": "PARTNER_COST_TYPE_THIRD_PARTY_AD_SERVER",
"feeType": "PARTNER_COST_FEE_TYPE_CPM_FEE",
"feeAmount": "1000000",
"invoiceType": "PARTNER_COST_INVOICE_TYPE_PARTNER"
},
{
"costType": "PARTNER_COST_TYPE_DOUBLE_VERIFY_PREBID",
"feeType": "PARTNER_COST_FEE_TYPE_CPM_FEE",
"feeAmount": "0",
"invoiceType": "PARTNER_COST_INVOICE_TYPE_DV360"
},
{
"costType": "PARTNER_COST_TYPE_DV360_FEE",
"feeType": "PARTNER_COST_FEE_TYPE_MEDIA_FEE",
"feePercentageMillis": "0",
"invoiceType": "PARTNER_COST_INVOICE_TYPE_DV360"
},
{
"costType": "PARTNER_COST_TYPE_DEFAULT",
"feeType": "PARTNER_COST_FEE_TYPE_MEDIA_FEE",
"feePercentageMillis": "0",
"invoiceType": "PARTNER_COST_INVOICE_TYPE_PARTNER"
}
],
"flight": {
"flightDateType": "LINE_ITEM_FLIGHT_DATE_TYPE_CUSTOM",
"dateRange": {
"startDate": {
"year": 2020,
"month": 4,
"day": 15
},
"endDate": {
"year": 2020,
"month": 4,
"day": 30
}
}
},
"budget": {
"budgetAllocationType": "LINE_ITEM_BUDGET_ALLOCATION_TYPE_UNLIMITED",
"budgetUnit": "BUDGET_UNIT_CURRENCY"
},
"pacing": {
"pacingPeriod": "PACING_PERIOD_DAILY",
"pacingType": "PACING_TYPE_EVEN",
"dailyMaxMicros": "26730000"
},
"frequencyCap": {
"timeUnit": "TIME_UNIT_DAYS",
"timeUnitCount": 1,
"maxImpressions": 5
},
"partnerRevenueModel": {
"markupType": "PARTNER_REVENUE_MODEL_MARKUP_TYPE_TOTAL_MEDIA_COST_MARKUP"
},
"conversionCounting": {
"postViewCountPercentageMillis": "100000"
},
"bidStrategy": {
"fixedBid": {
"bidAmountMicros": "3610000"
}
},
"integrationDetails": {}
}
]
}
de floodlightActivityConfigs necesito que estas matrices estén en una celda como
{ "1fI": "72217193", "3PCdays": 30, "2PVdays": 30 },{ "1fI": "75221840", "3PCdays": 30, "2PVdays": 30 }, { "1fI": "75222864", "3PCdays": 30, "2PVdays": 30 }, { "1fI": "75333184", "3PCdays": 30, "2PVdays": 30 }
sin embargo, cuando trato de presionarlos, solo se imprime la primera parte, del ejemplo JSON, el segundo objeto no tiene detalles de floodlightActivityConfigs y esto se espera
Mi código está debajo con el JSON incrustado, simplemente no puedo entender esto
function testAPI2(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Mysheet');
var response = {"lineItems":[{"name":"advertisers/1558261/lineItems/12317016","advertiserId":"1238261","campaignId":"1233305","insertionOrderId":"13016372","lineItemId":"12317016","displayName":"All | Routes| All Users | ABC | ABC-LI1","lineItemType":"LINE_ITEM_TYPE_DISPLAY_DEFAULT","entityStatus":"ENTITY_STATUS_ACTIVE","updateTime":"2020-04-15T12:51:42.929Z","partnerCosts":[{"costType":"PARTNER_COST_TYPE_THIRD_PARTY_AD_SERVER","feeType":"PARTNER_COST_FEE_TYPE_CPM_FEE","feeAmount":"1000000","invoiceType":"PARTNER_COST_INVOICE_TYPE_PARTNER"},{"costType":"PARTNER_COST_TYPE_DOUBLE_VERIFY_PREBID","feeType":"PARTNER_COST_FEE_TYPE_CPM_FEE","feeAmount":"0","invoiceType":"PARTNER_COST_INVOICE_TYPE_DV360"},{"costType":"PARTNER_COST_TYPE_DV360_FEE","feeType":"PARTNER_COST_FEE_TYPE_MEDIA_FEE","feePercentageMillis":"0","invoiceType":"PARTNER_COST_INVOICE_TYPE_DV360"},{"costType":"PARTNER_COST_TYPE_DEFAULT","feeType":"PARTNER_COST_FEE_TYPE_MEDIA_FEE","feePercentageMillis":"0","invoiceType":"PARTNER_COST_INVOICE_TYPE_PARTNER"}],"flight":{"flightDateType":"LINE_ITEM_FLIGHT_DATE_TYPE_CUSTOM","dateRange":{"startDate":{"year":2020,"month":4,"day":15},"endDate":{"year":2020,"month":4,"day":30}}},"budget":{"budgetAllocationType":"LINE_ITEM_BUDGET_ALLOCATION_TYPE_UNLIMITED","budgetUnit":"BUDGET_UNIT_CURRENCY"},"pacing":{"pacingPeriod":"PACING_PERIOD_DAILY","pacingType":"PACING_TYPE_EVEN","dailyMaxMicros":"40100000"},"frequencyCap":{"timeUnit":"TIME_UNIT_DAYS","timeUnitCount":1,"maxImpressions":5},"partnerRevenueModel":{"markupType":"PARTNER_REVENUE_MODEL_MARKUP_TYPE_TOTAL_MEDIA_COST_MARKUP"},"conversionCounting":{"postViewCountPercentageMillis":"100000","floodlightActivityConfigs":[{"1fI":"7517101","3PCdays":30,"2PVdays":30},{"1fI":"7541802","3PCdays":30,"2PVdays":30},{"1fI":"7552803","3PCdays":30,"2PVdays":30},{"1fI":"7517104","3PCdays":30,"2PVdays":30}]},"bidStrategy":{"fixedBid":{"bidAmountMicros":"3610000"}},"integrationDetails":{}},{"name":"advertisers/1558261/lineItems/12317017","advertiserId":"1238261","campaignId":"1233305","insertionOrderId":"13016372","lineItemId":"12317017","displayName":"All | Routes| All Users | ABC | ABC-LI2","lineItemType":"LINE_ITEM_TYPE_DISPLAY_DEFAULT","entityStatus":"ENTITY_STATUS_ACTIVE","updateTime":"2020-04-01T16:06:19.831Z","partnerCosts":[{"costType":"PARTNER_COST_TYPE_THIRD_PARTY_AD_SERVER","feeType":"PARTNER_COST_FEE_TYPE_CPM_FEE","feeAmount":"1000000","invoiceType":"PARTNER_COST_INVOICE_TYPE_PARTNER"},{"costType":"PARTNER_COST_TYPE_DOUBLE_VERIFY_PREBID","feeType":"PARTNER_COST_FEE_TYPE_CPM_FEE","feeAmount":"0","invoiceType":"PARTNER_COST_INVOICE_TYPE_DV360"},{"costType":"PARTNER_COST_TYPE_DV360_FEE","feeType":"PARTNER_COST_FEE_TYPE_MEDIA_FEE","feePercentageMillis":"0","invoiceType":"PARTNER_COST_INVOICE_TYPE_DV360"},{"costType":"PARTNER_COST_TYPE_DEFAULT","feeType":"PARTNER_COST_FEE_TYPE_MEDIA_FEE","feePercentageMillis":"0","invoiceType":"PARTNER_COST_INVOICE_TYPE_PARTNER"}],"flight":{"flightDateType":"LINE_ITEM_FLIGHT_DATE_TYPE_CUSTOM","dateRange":{"startDate":{"year":2020,"month":4,"day":15},"endDate":{"year":2020,"month":4,"day":30}}},"budget":{"budgetAllocationType":"LINE_ITEM_BUDGET_ALLOCATION_TYPE_UNLIMITED","budgetUnit":"BUDGET_UNIT_CURRENCY"},"pacing":{"pacingPeriod":"PACING_PERIOD_DAILY","pacingType":"PACING_TYPE_EVEN","dailyMaxMicros":"26730000"},"frequencyCap":{"timeUnit":"TIME_UNIT_DAYS","timeUnitCount":1,"maxImpressions":5},"partnerRevenueModel":{"markupType":"PARTNER_REVENUE_MODEL_MARKUP_TYPE_TOTAL_MEDIA_COST_MARKUP"},"conversionCounting":{"postViewCountPercentageMillis":"100000"},"bidStrategy":{"fixedBid":{"bidAmountMicros":"3610000"}},"integrationDetails":{}}]};
var data = JSON.parse(JSON.stringify(response));
var LiData = data["lineItems"];
var rows = [],
data;
for (i = 0; i < LiData.length; i++) {
data = LiData[i];
rows.push([
data.campaignId,
data.conversionCounting.floodlightActivityConfigs
]);
}
dataRange = sheet.getRange(2, 1, rows.length,2).setValues(rows);
}
Creo que su objetivo es el siguiente.
{ "1fI": "72217193", "3PCdays": 30, "2PVdays": 30 },,,
en una celda.Para esto, ¿qué tal esta modificación?
data.conversionCounting.floodlightActivityConfigs
hay una matriz. Para poner esto en una celda, utilice JSON.stringify
. Creo que el motivo de su problema es este.Cuando esto se refleje en su script, modifíquelo de la siguiente manera.
rows.push([
data.campaignId,
data.conversionCounting.floodlightActivityConfigs
]);
A:
rows.push([
data.campaignId,
JSON.stringify(data.conversionCounting.floodlightActivityConfigs)
]);
{ "1fI": "72217193", "3PCdays": 30, "2PVdays": 30 }
a { "1fI": "72217193", "2PVdays": 30,"3PCdays": 30... }
.Desafortunadamente, no se garantiza el orden del objeto JSON. Por ejemplo, este hilo es útil para comprenderlo.
Pero, en su caso, desea poner el objeto en una celda como una cadena. Pensé que esto se puede utilizar para resolver su pregunta adicional. Entonces, como solución temporal, cuando { "1fI": "72217193", "3PCdays": 30, "2PVdays": 30 }
no se usa como objeto JSON, creo que se puede establecer el orden.
rows.push([
data.campaignId,
data.conversionCounting.floodlightActivityConfigs
]);
A:
rows.push([
data.campaignId,
data.conversionCounting.floodlightActivityConfigs ? `[${data.conversionCounting.floodlightActivityConfigs.map(e => `{${Object.entries(e).map(([k, v]) => typeof v == "number" ? `"${k}":${v}` : `"${k}":"${v}"`).sort().join(",")}}`).join(",")}]` : ""
]);
En este caso, se coloca el siguiente valor en la celda.
[{"1fI":"7517101","2PVdays":30,"3PCdays":30},{"1fI":"7541802","2PVdays":30,"3PCdays":30},{"1fI":"7552803","2PVdays":30,"3PCdays":30},{"1fI":"7517104","2PVdays":30,"3PCdays":30}]
La estrella de HGTV, Christina Hall, revela que le diagnosticaron envenenamiento por mercurio y plomo, probablemente debido a su trabajo como manipuladora de casas.
Recientemente salió a la luz un informe policial que acusa a la estrella de 'Love Is Blind', Brennon, de violencia doméstica. Ahora, Brennon ha respondido a los reclamos.
Conozca cómo Wynonna Judd se dio cuenta de que ahora es la matriarca de la familia mientras organizaba la primera celebración de Acción de Gracias desde que murió su madre, Naomi Judd.
Descubra por qué un destacado experto en lenguaje corporal cree que es fácil trazar "tales paralelismos" entre la princesa Kate Middleton y la princesa Diana.
Los inodoros arrojan columnas de aerosol invisibles con cada descarga. ¿Como sabemos? La prueba fue capturada por láseres de alta potencia.
Air travel is far more than getting from point A to point B safely. How much do you know about the million little details that go into flying on airplanes?
The world is a huge place, yet some GeoGuessr players know locations in mere seconds. Are you one of GeoGuessr's gifted elite? Take our quiz to find out!
¿Sigue siendo efectivo ese lote de repelente de insectos que te quedó del verano pasado? Si es así, ¿por cuánto tiempo?
Durante mucho tiempo, el mundo se ha reído de la voz de Peter Dinklage actuando en Destiny, un videojuego sobre la lenta e inevitable progresión de la muerte. Pronto, esa actuación de voz va a cambiar.
Tapas elásticas de silicona de Tomorrow's Kitchen, paquete de 12 | $14 | Amazonas | Código promocional 20OFFKINJALids son básicamente los calcetines de la cocina; siempre perdiéndose, dejando contenedores huérfanos que nunca podrán volver a cerrarse. Pero, ¿y si sus tapas pudieran estirarse y adaptarse a todos los recipientes, ollas, sartenes e incluso frutas en rodajas grandes que sobran? Nunca más tendrás que preocuparte por perder esa tapa tan específica.
Hemos pirateado algunas ciudades industriales en esta columna, como Los Ángeles y Las Vegas. Ahora es el momento de una ciudad militar-industrial-compleja.
Un minorista está enlatando su sección de tallas grandes. Pero no están tomando la categoría solo en línea o descontinuándola por completo.
El equipo está a la espera de las medallas que ganó en los Juegos Olímpicos de Invierno de 2022 en Beijing, ya que se está resolviendo un caso de dopaje que involucra a la patinadora artística rusa Kamila Valieva.
Miles de compradores de Amazon recomiendan la funda de almohada de seda Mulberry, y está a la venta en este momento. La funda de almohada de seda viene en varios colores y ayuda a mantener el cabello suave y la piel clara. Compre las fundas de almohada de seda mientras tienen hasta un 46 por ciento de descuento en Amazon
El jueves se presentó una denuncia de delito menor amenazante agravado contra Joe Mixon.
El Departamento de Policía de Lafayette comenzó a investigar a un profesor de la Universidad de Purdue en diciembre después de recibir varias denuncias de un "hombre sospechoso que se acercaba a una mujer".
Al igual que el mundo que nos rodea, el lenguaje siempre está cambiando. Mientras que en eras anteriores los cambios en el idioma ocurrían durante años o incluso décadas, ahora pueden ocurrir en cuestión de días o incluso horas.
Estoy de vuelta por primera vez en seis años. No puedo decirte cuánto tiempo he estado esperando esto.
“And a river went out of Eden to water the garden, and from thence it was parted and became into four heads” Genesis 2:10. ? The heart is located in the middle of the thoracic cavity, pointing eastward.
Creo, un poco tarde en la vida, en dar oportunidades a la gente. Generosamente.