Ich entwickle einen WCF-Dienst. In diesem Dienst muss ich ein Array mit jedem Index zurückgeben. Aber ich habe zufällig einen Fall (kann in diesem Fall sehr viel sein), wo ein Index einen oder mehrere Daten haben kann. Ich erkläreWörterbuch in C# doppelten Schlüssel
Ich habe eine Klasse Indicator
public class Indicador
{
[DataMember]
public string indicador_nombre { get; set; }
[DataMember]
public string indicador_codigo { get; set; }
[DataMember]
public string indicador_tipo { get; set; }
[DataMember]
public string indicador_descripcion { get; set; }
[DataMember]
public Dictionary<string, List<Celda>> celdas { get; set; }
}
Dieser Indikator ein Wörterbuch hat, die eine string
und eine Liste der Celdas
enthält.
public class Celda
{
[DataMember]
public int celda_id { get; set; }
[DataMember]
public string celda_codigo_empresa { get; set; }
[DataMember]
public string celda_modulo_codigo { get; set; }
[DataMember]
public int celda_orden { get; set; }
[DataMember]
public string celda_categoria_nombre { get; set; }
[DataMember]
public string celda_categoria_codigo { get; set; }
[DataMember]
public List<CeldaKeyVal> valores_celdas { get; set; }
}
Celda
hat auch eine Liste von CeldaKeyVal
public class CeldaKeyVal
{
[DataMember]
public string celda_key_codigo { get; set; }
[DataMember]
public string celda_key_valor { get; set; }
}
Nun, zum Beispiel ich habe folgendes:
{
"GetCheckInResult": {
"indicadores": [
{
"celdas": [
{
"Key": "I001",
"Value": [
{
"celda_categoria_codigo": "C01",
"celda_categoria_nombre": "Cecina",
"celda_codigo_empresa": "E0001",
"celda_id": 1,
"celda_modulo_codigo": "M01",
"celda_orden": 1,
"valores_celdas": [
{
"celda_key_codigo": "CODIGO",
"celda_key_valor": "CHECK1"
},
{
"celda_key_codigo": "IMAGEN",
"celda_key_valor": "L76nD.jpg"
},
{
"celda_key_codigo": "SUBTEXTO",
"celda_key_valor": "prueba subtexto 1"
},
{
"celda_key_codigo": "TEXTO",
"celda_key_valor": "Prueba dominio 1"
}
]
}
]
}
],
"indicador_codigo": "I001",
"indicador_descripcion": "Foto SKU + Descrip.SKU + EAN13 + Sí/No",
"indicador_nombre": "Presencia",
"indicador_tipo": "T01"
},
{
"celdas": [
{
"Key": "I002",
"Value": [
{
"celda_categoria_codigo": "C02",
"celda_categoria_nombre": "Cerdo",
"celda_codigo_empresa": "E0001",
"celda_id": 4,
"celda_modulo_codigo": "M01",
"celda_orden": 1,
"valores_celdas": [
{
"celda_key_codigo": "CODIGO",
"celda_key_valor": "codigo"
}
]
}
]
}
],
"indicador_codigo": "I002",
"indicador_descripcion": "Descrip. + Cantidad",
"indicador_nombre": "Precio",
"indicador_tipo": "T03"
},
{
"celdas": [
{
"Key": "I002",
"Value": [
{
"celda_categoria_codigo": "C01",
"celda_categoria_nombre": "Cecina",
"celda_codigo_empresa": "E0001",
"celda_id": 5,
"celda_modulo_codigo": "M01",
"celda_orden": 4,
"valores_celdas": [
{
"celda_key_codigo": "CODIGO",
"celda_key_valor": "ssddsds"
}
]
}
]
}
],
"indicador_codigo": "I002",
"indicador_descripcion": "Descrip. + Cantidad",
"indicador_nombre": "Precio",
"indicador_tipo": "T03"
},
{
"celdas": [
{
"Key": "I003",
"Value": [
{
"celda_categoria_codigo": "C01",
"celda_categoria_nombre": "Cecina",
"celda_codigo_empresa": "E0001",
"celda_id": 3,
"celda_modulo_codigo": "M01",
"celda_orden": 6,
"valores_celdas": [
{
"celda_key_codigo": "CODIGO",
"celda_key_valor": "sdadsa"
},
{
"celda_key_codigo": "IMAGEN",
"celda_key_valor": "L76nD.jpg"
},
{
"celda_key_codigo": "TEXTO",
"celda_key_valor": "Texto 1"
}
]
}
]
}
],
"indicador_codigo": "I003",
"indicador_descripcion": "Foto + Sí/No",
"indicador_nombre": "Actividades Claves",
"indicador_tipo": "T02"
}
],
"status": 1
}
}
Wenn ich die key I002
erkennen, zwei Celdas
... dann möchte ich, dass zwei Celdas
waren in der gleichen key
und nicht separat.
Zuerst initialisierte ich das Wörterbuch für jede Iteration des Abfrageergebnisses meines SP. aber scheitert und zeigt eine solche Anordnung zum Stoppen an. Wenn ich initialisiere außerhalb meiner für, dh einmal, erzeugt mehrere Ergebnisse und wenn es falsch ist. Versuchen Sie, so spezifisch wie möglich zu sein, keine Fragen zögern Sie nicht zu kommentieren!
Der Code, der das Wörterbuch auffüllt, wie sieht das aus? – radarbob