[Fixed] Json naar database

Gestart doorChristum3 reacties344 weergaven

4 berichten · pagina 1 van 1

Christum

Lid · Topicstarter

Berichten
921
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Beste,

Momenteel ben ik bezig om een script in elkaar te zetten om een json file (+/- 4000 regels en 15000 tekens) om te zetten naar de database.
Helaas krijg ik maar een beperkt aantal gegevens terug en krijg ik via internet niet voldoende duidelijkheid hoe ik dit kan oplossen.

Json code (Stukje ervan)

{
  "base-info": {
    "identifier": "ultimatecore",
    "name": "UltimateCore",
    "version": "3.0.8-SNAPSHOT"
  },
  "modules": [
    {
      "identifier": "kick",
      "description": "Allows you to kick a player from the server.",
      "enabledbydefault": true,
      "hasconfig": false
    }, 
    {
      "identifier": "burn",
      "description": "Set a player on fire using the /burn command.",
      "enabledbydefault": true,
      "hasconfig": false
    }
  ],
  "commands": [
    {
      "identifier": "kick",
      "description": "Kick a player from the server.",
      "aliases": [
        "kick"
      ],
      "module": "kick",
      "basepermissions": "uc.kick.kick.base",
      "permissions": [
        "uc.kick.kick.base"
      ],
      "usage": "/kick <Player> [Reason]"
    },
    {
      "identifier": "kickall",
      "description": "Kick all players from the server.",
      "aliases": [
        "kickall",
        "kickeveryone"
      ],
      "module": "kick",
      "basepermissions": "uc.kick.kickall.base",
      "permissions": [
        "uc.kick.kickall.base"
      ],
      "usage": "/kickall [Reason]"
    },
    {
      "identifier": "burn",
      "description": "Set people on fire.",
      "aliases": [
        "burn",
        "fire",
        "ignite"
      ],
      "module": "burn",
      "basepermissions": "uc.burn.burn.base",
      "permissions": [
        "uc.burn.burn.base"
      ],
      "usage": "/burn <Player> [Time]"
    }
  ]
}


PHP code (Debug/controle script)

[COLOR= #0000BB]<?php[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$jsondata[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]http://pastebin.com/raw/96qJtGNS[/COLOR][COLOR= #007700]);[/COLOR]
        [COLOR= #0000BB]$data[/COLOR] [COLOR= #007700]=[/COLOR] json_decode[COLOR= #007700]([/COLOR][COLOR= #0000BB]$jsondata[/COLOR][COLOR= #007700],[/COLOR] true[COLOR= #007700]);[/COLOR]

            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<br><br><br>Base-info: indentifier <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow1[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]base-info[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]identifier[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Base-info: name <strong>[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$datarow2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]base-info[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]name[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Base-info: version <strong>[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$datarow3[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]base-info[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]version[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Modules: indentifier <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow4[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]modules[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]identifier[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Modules: desc <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow5[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]modules[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]description[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Modules: enabled default <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow6[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]modules[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]enabledbydefault[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Modules: config <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow7[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]modules[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]hasconfig[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Commands: indentifier <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow8[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]commands[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]identifier[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]postalcode[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Commands: desc <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow9[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]commands[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]description[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Commands: alias <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow10[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]commands[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]aliases[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Commands: module <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow11[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]commands[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]module[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Commands: baseperm <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow12[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]commands[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]basepermissions[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Commands: perms <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow13[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]commands[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]permissions[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Commands: usage <strong>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$datarow14[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]commands[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]usage[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]</strong><br>[/COLOR][COLOR= #007700];[/COLOR]
?>


Output

Base-info: indentifier ultimatecore
Base-info: name UltimateCore
Base-info: version 3.0.8-SNAPSHOT
Modules: indentifier 
Modules: desc 
Modules: enabled default 
Modules: config 
Commands: indentifier 
Commands: desc 
Commands: alias 
Commands: module 
Commands: baseperm 
Commands: perms 
Commands: usage


Volgens mij zie ik in het php deel iets over het hoofd maar ik weet niet wat omdat ik nog weinig ervaring heb met json omzetten.
0
Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je doet een variable een waarde geven in je echo, dit geeft niks terug. Je moet de $xxx = ervoor weglaten.
0
Berichten
3.112
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Milan schreef:
Je doet een variable een waarde geven in je echo, dit geeft niks terug. Je moet de $xxx = ervoor weglaten.
Daar is niets mis mee?

[COLOR= #0000BB]<?[/COLOR]php
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]one [/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$b[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]2[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000] xs[/COLOR][COLOR= #007700];[/COLOR]
// Geeft gewoon one2xs


De code van @Christum werkt niet omdat $data[modules][description] niet bestaat, maar $data[modules][0][description]`
0
Christum

Lid · Topicstarter

Berichten
921
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Milan schreef:
Je doet een variable een waarde geven in je echo, dit geeft niks terug. Je moet de $xxx = ervoor weglaten.

Die echo staat er puur en alleen omheen voor debug de $xxx heeft later wel een functie.
Perry schreef:
Eerdere citaten tonen
Milan schreef:
Je doet een variable een waarde geven in je echo, dit geeft niks terug. Je moet de $xxx = ervoor weglaten.
Daar is niets mis mee?

[COLOR= #0000BB]<?[/COLOR]php
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]one [/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$b[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]2[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000] xs[/COLOR][COLOR= #007700];[/COLOR]
// Geeft gewoon one2xs


De code van @Christum werkt niet omdat $data[modules][description] niet bestaat, maar $data[modules][0][description]`
Kijk, ik heb dus duidelijk die [0] over het hoofd gezien, het werkt nu!

Thanks!
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren