Autor Tema: JSON  (Leído 4210 veces)

0 Usuarios y 1 Visitante están viendo este tema.

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
JSON
« en: Diciembre 03, 2011, 04:31:20 pm »
Hola no se como obtener datos con json tengo este script

Código: [Seleccionar]
{"response":{"timestamp":1322936507,"base":{"id":1136693,"name":"First Base","resources":{"crystal":2800,"gas":2718,"energy":2746,"uranium":2562,"capacity":11000,"crystal_rate":10,"gas_rate":10,"energy_rate":10,"uranium_rate":10},"buildings":[{"id":16676625,"base_id":1136693,"type":"Barracks","x":590,"y":370,"level":1,"hp":500},{"id":16671244,"base_id":1136693,"type":"CommandCenter","x":340,"y":280,"level":2,"hp":600},{"id":16671247,"base_id":1136693,"type":"CrystalMine","x":410,"y":100,"level":1,"hp":100,"amount":600},{"id":16676335,"base_id":1136693,"type":"FusionReactor","x":400,"y":200,"level":1,"hp":100,"amount":600},{"id":16671248,"base_id":1136693,"type":"GasRefinery","x":410,"y":470,"level":1,"hp":100,"amount":600},{"id":16671848,"base_id":1136693,"type":"GunTurret","x":780,"y":360,"level":1,"hp":300},{"id":16672690,"base_id":1136693,"type":"GunTurret","x":150,"y":520,"level":2,"hp":480},{"id":16676098,"base_id":1136693,"type":"SolarPlant","x":330,"y":440,"level":1,"hp":100,"amount":600},{"id":16671245,"base_id":1136693,"type":"StagingArea","x":470,"y":350,"level":1,"hp":450},{"id":18177598,"base_id":1136693,"type":"StagingArea","x":510,"y":470,"level":1,"hp":450},{"id":18177413,"base_id":1136693,"type":"SupplyDepot","x":510,"y":150,"level":1,"hp":300},{"id":16676929,"base_id":1136693,"type":"TechLab","x":280,"y":170,"level":1,"hp":100},{"warps_available":3,"id":16671246,"base_id":1136693,"type":"WarpGate","x":530,"y":250,"level":1,"hp":100},{"id":18178062,"base_id":1136693,"type":"X1Cannon","x":110,"y":130,"level":1,"hp":800},{"id":18179007,"base_id":1136693,"type":"X1Cannon","x":690,"y":140,"level":1,"hp":800}],"boosts":[],"permanent_armor":false,"permanent_attack":false,"units":[{"id":16527328,"type":"Marine","level":2,"quantity":39}],"unit_queues":[],"protection_type":"none","protected_until":1322720036,"terrain_artifacts":{"craters":[{"x":674.6,"y":477.1,"length":826.262409891676},{"x":703.3,"y":439.65,"length":829.4112444981681},{"x":698.15,"y":459.85,"length":835.9877062493205},{"x":701.55,"y":454.65,"length":835.9898474263906},{"x":480,"y":540,"length":722.4956747275377},{"x":-20,"y":340,"length":340.58772731852804},{"x":0,"y":330,"length":330},{"x":20,"y":260,"length":260.76809620810593},{"x":-200,"y":210,"length":290},{"x":-100,"y":160,"length":188.67962264113208}]}},"id":1136698,"name":"red phil","level":6,"is_playing":false,"damage_protection":false,"hp_boost":1.6,"damage_boost":1.6,"xp":16630,"next_level_xp":21000,"current_level_xp":15000,"free_lotto_play":true,"last_login":1322256755,"user_created_at":1316619384,"x":"05bacb06cba821765c622bd3f1fe669af2dd71a5"},"x":"7ed6fa198644ab159695d43c20da1a3efffef589","y":"5a56425acfff7324d1dbe54989c70b063c04340f"}
Como puedo obtener el valor que tiene "crystal" o "energy"

Saludos.

seba123neo

  • Terabyte
  • *****
  • Mensajes: 763
  • Reputación: +88/-5
    • Ver Perfil
Re:JSON
« Respuesta #1 en: Diciembre 03, 2011, 04:43:39 pm »
no se si te sirva, yo 0 de PHP

Parsing JSON file with PHP

saludos.

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:JSON
« Respuesta #2 en: Diciembre 03, 2011, 09:21:54 pm »
Gracias Seba si vi los ejemplos de la web se que se utiliza json_decode pero se como acceder a los resultados, en los intentos que hice no obtuve nada.

Saludos.

raul338

  • Terabyte
  • *****
  • Mensajes: 894
  • Reputación: +62/-8
  • xD fan!!!!! xD
    • Ver Perfil
    • Raul's Weblog
Re:JSON
« Respuesta #3 en: Diciembre 04, 2011, 04:54:47 am »
echo $json["response"]["base"]["resources"]["crystal"];

Deberia funcionar, creo :P (son casi las 5 x'D)

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:JSON
« Respuesta #4 en: Diciembre 04, 2011, 03:41:55 pm »
Perfecto Raul me estaban faltando las comillas.

Saludos.

coco

  • Administrador
  • Terabyte
  • *****
  • Mensajes: 548
  • Reputación: +63/-3
    • Ver Perfil
Re:JSON
« Respuesta #5 en: Diciembre 05, 2011, 10:31:26 pm »
Leandro, por si te interesa, aca esta la version para VB6:
VB JSON Parser Library
funciona muy parecido al de PHP
'-     coco
(No me cabe: Java, Python ni Pascal)
SQLite - PIC 16F y 18F - ARM STM32 - ESP32 - Linux Embebido - VB6 - Electronica - Sonido y Ambientacion