Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 04-07-2019
Avatar de ingabraham
ingabraham ingabraham is offline
Miembro
 
Registrado: ago 2007
Posts: 614
Poder: 17
ingabraham Va por buen camino
convertir json a xml

buenas necesito convertir una estructura json a xml.
gracias
ejemplo:
Código:
{
  "email": {
    "mensaje": {
      "remite": {
        "nombre": "Alfredo Reino",
        "email": "alf@ibium.com"
      },
      "destinatario": {
        "nombre": "Bill Clinton",
        "email": "president@whitehouse.gov"
      },
      "asunto": "Hola Bill",
      "texto": {
        "parrafo": {
          "#text": [
            "¿Hola qué tal? Hace ",
            " que no escribes. A ver si llamas y quedamos para tomar algo."
          ],
          "enfasis": "mucho"
        }
      }
    }
  }
}
convertido a:


Código:
<?xml version="1.0" encoding="UTF-8" ?>
	<email>
		<mensaje>
			<remite>
				<nombre>Alfredo Reino</nombre>
				<email>alf@ibium.com</email>
			</remite>
			<destinatario>
				<nombre>Bill Clinton</nombre>
				<email>president@whitehouse.gov</email>
			</destinatario>
			<asunto>Hola Bill</asunto>
			<texto>
				<parrafo>
					¿Hola qué tal? Hace  que no escribes. A ver si llamas y quedamos para tomar algo.<enfasis>mucho</enfasis>
				</parrafo>
			</texto>
		</mensaje>
	</email>
__________________
Enseñar es la virtud de un sabio.
Responder Con Cita
  #3  
Antiguo 04-07-2019
Avatar de ingabraham
ingabraham ingabraham is offline
Miembro
 
Registrado: ago 2007
Posts: 614
Poder: 17
ingabraham Va por buen camino
gracias amigo. pero es para realizar las funciones en delphi. no externo a delphi
muchas gracias
__________________
Enseñar es la virtud de un sabio.
Responder Con Cita
  #4  
Antiguo 05-07-2019
Avatar de ingabraham
ingabraham ingabraham is offline
Miembro
 
Registrado: ago 2007
Posts: 614
Poder: 17
ingabraham Va por buen camino
Unhappy

por ejemplo recorrer un json e ir armando un xml en delphi
__________________
Enseñar es la virtud de un sabio.
Responder Con Cita
  #5  
Antiguo 05-07-2019
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.020
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Creo que no has leído mi respuesta anterior
Responder Con Cita
  #6  
Antiguo 05-07-2019
Avatar de ingabraham
ingabraham ingabraham is offline
Miembro
 
Registrado: ago 2007
Posts: 614
Poder: 17
ingabraham Va por buen camino
Cita:
Empezado por Casimiro Notevi Ver Mensaje
Creo que no has leído mi respuesta anterior
gracias por tu atencion,. amigo solo baja un ejecutable. no esta el codigo fuente delphi!
__________________
Enseñar es la virtud de un sabio.
Responder Con Cita
  #7  
Antiguo 05-07-2019
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.020
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Habría jurado que estaba
No sé si con los últimos delphi se puede.
Mira esto, a ver si te sirve, no sé en qué lenguaje está.
Responder Con Cita
  #8  
Antiguo 05-07-2019
Avatar de ingabraham
ingabraham ingabraham is offline
Miembro
 
Registrado: ago 2007
Posts: 614
Poder: 17
ingabraham Va por buen camino
ENCONTRE ESTA funcion que recorre todo el json , con sus array.
en una unit llamada jsontreeview .
tocaria ir armando el xml o algo asi. si tienen ideas


Código Delphi [-]
procedure TJSONTreeView.LoadJson;
var v: TJSONValue; currNode: TTreeNode; i, aCount: integer; s: string;
begin
  ClearAll;

  if (JSONDocument <> nil) and JSONDocument.IsActive then
  begin
    v := JSONDocument.RootValue;
    Items.Clear;

    if TJSONDocument.IsSimpleJsonValue(v) then
      Items.AddChild(nil, TJSONDocument.UnQuote(v.Value))

    else
    if v is TJSONObject then
    begin
      aCount := TJSONObject(v).Size;
      s := '{}';
      if VisibleChildrenCounts then
        s := s + ' (' + IntToStr(aCount) + ')';
      if VisibleByteSizes then
        s := s + ' (size: ' + IntToStr(v.EstimatedByteSize) + ' bytes)';
      currNode := Items.AddChild(nil, s);
      for i := 0 to aCount - 1 do
        ProcessPair(currNode, TJSONObject(v), i)
    end

    else
    if v is TJSONArray then
    begin
      aCount := TJSONArray(v).Size;
      s := '[]';
      if VisibleChildrenCounts then
        s := s + ' (' + IntToStr(aCount) + ')';
      if VisibleByteSizes then
        s := s + ' (size: ' + IntToStr(v.EstimatedByteSize) + ' bytes)';
      currNode := Items.AddChild(nil, s);
      for i := 0 to aCount - 1 do
        ProcessElement(currNode, TJSONArray(v), i)
    end

    else
      raise EUnknownJsonValueDescendant.Create;

    FullExpand;
  end;
end;

procedure TJSONTreeView.ProcessPair(currNode: TTreeNode; obj: TJSONObject; aIndex: integer);
var p: TJSONPair; s: string; n: TTreeNode; i, aCount: integer;
begin
  p := obj.Get(aIndex);

  s := TJSONDocument.UnQuote(p.JsonString.ToString) + ' : ';

  if TJSONDocument.IsSimpleJsonValue(p.JsonValue) then
  begin
    Items.AddChild(currNode, s + p.JsonValue.ToString);
    exit;
  end;

  if p.JsonValue is TJSONObject then
  begin
    aCount := TJSONObject(p.JsonValue).Size;
    s := s + ' {}';
    if VisibleChildrenCounts then
      s := s + ' (' + IntToStr(aCount) + ')';
    if VisibleByteSizes then
        s := s + ' (size: ' + IntToStr(p.EstimatedByteSize) + ' bytes)';
    n := Items.AddChild(currNode, s);
    for i := 0 to aCount - 1 do
      ProcessPair(n, TJSONObject(p.JsonValue), i);
  end

  else if p.JsonValue is TJSONArray then
  begin
    aCount := TJSONArray(p.JsonValue).Size;
    s := s + ' []';
    if VisibleChildrenCounts then
      s := s + ' (' + IntToStr(aCount) + ')';
    if VisibleByteSizes then
        s := s + ' (size: ' + IntToStr(p.EstimatedByteSize) + ' bytes)';
    n := Items.AddChild(currNode, s);
    for i := 0 to aCount - 1 do
      ProcessElement(n, TJSONArray(p.JsonValue), i);
  end
  else
    raise EUnknownJsonValueDescendant.Create;
end;

procedure TJSONTreeView.ProcessElement(currNode: TTreeNode; arr: TJSONArray; aIndex: integer);
var v: TJSONValue; s: string; n: TTreeNode; i, aCount: integer;
begin
  v := arr.Get(aIndex);
  s := '[' + IntToStr(aIndex) + '] ';

  if TJSONDocument.IsSimpleJsonValue(v) then
  begin
    Items.AddChild(currNode, s + v.ToString);
    exit;
  end;

  if v is TJSONObject then
  begin
    aCount := TJSONObject(v).Size;
    s := s + ' {}';
    if VisibleChildrenCounts then
      s := s + ' (' + IntToStr(aCount) + ')';
    if VisibleByteSizes then
        s := s + ' (size: ' + IntToStr(v.EstimatedByteSize) + ' bytes)';
    n := Items.AddChild(currNode, s);
    for i := 0 to aCount - 1 do
      ProcessPair(n, TJSONObject(v), i);
  end

  else if v is TJSONArray then
  begin
    aCount := TJSONArray(v).Size;
    s := s + ' []';
    n := Items.AddChild(currNode, s);
    if VisibleChildrenCounts then
      s := s + ' (' + IntToStr(aCount) + ')';
    if VisibleByteSizes then
        s := s + ' (size: ' + IntToStr(v.EstimatedByteSize) + ' bytes)';
    for i := 0 to aCount - 1 do
      ProcessElement(n, TJSONArray(v), i);
  end
  else
    raise EUnknownJsonValueDescendant.Create;

end;
__________________
Enseñar es la virtud de un sabio.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
extracción en JSON Ulises PHP 9 16-10-2018 21:46:28
consulta json D1360666 Desarrollo en Delphi para Android 6 17-02-2016 17:16:25
Problemón con JSON MaxiDucoli OOP 7 25-09-2015 18:54:39
Json de PHP a Imagen Kubelo Gráficos 5 20-06-2014 10:05:59
Fecha JSON. BuenaOnda Varios 4 27-11-2011 19:46:27


La franja horaria es GMT +2. Ahora son las 10:13:11.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi