Avatar of 3xtr3m3d
3xtr3m3d

asked on 

help needed in building json data

Hi

any idea how to build this structure with json using php

"data" : [
				{ 
					"data" : "My Documents", 
					"children" : [ {"attr":{"id":"2","rel":"file"},"data":"file1.doc","state":""} ]
				}
			]

Open in new window


Thanks
PHPJavaScriptJoomla

Avatar of undefined
Last Comment
3xtr3m3d
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Use json_encode:
http://us3.php.net/manual/en/function.json-encode.php

Refer to the example sections on that page

Avatar of Proculopsis
Proculopsis


//Something like this:

$o = array( "data" => array(
  "data" => "My Documents",
  "children" => array(
    "attr" => array(
      "id" => 2,
      "rel" => "file"
      ),
      "data" => "file1.doc",
      "state" => ""
    )
  )
);

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of 3xtr3m3d
3xtr3m3d

ASKER

Hi

Thanks all for the replies guys.

hielo: thanks i changed your solution like this and it works

$obj = array(
				array(
								"data" => "My Documents",
								"children" => array(
													array(
															"attr" => array(
																			"id" => 2,
																			"rel" => "file"
																		),
															"data" => "file1.doc",
															"state" => ""
														)
											)
								)
						
		);
		
echo json_encode($obj);

Open in new window


any idea how to build this with two mysql queries? like getting
"data" => "My Documents"  from 1 query and contents for children with second query.

Thanks
Avatar of hielo
hielo
Flag of Wallis and Futuna image

It sounds like you will need nested while loops.  Open a new thread and post your php code related to these queries.
Avatar of 3xtr3m3d
3xtr3m3d

ASKER

Thanks posted new question on

New Question
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo