I am working with the Twitter API and finding it great fun and generally easy to use.
But I am having trouble getting to the data in the trends/current.json file. I am able to loop through the object data with a foreach loop and print it out. But I want to do more with the data than just print it.
Just to be clear, I want to work with the daily and weekly trends but I am using the simpler current trends for this example. What I want to do is get the data out so that I can sort it, count duplicates, and remove duplicates.
Here is my code: -
$json = file_get_contents("http://search.twitter.com/trends/current.json",0,null,null);
-
$json = json_decode($json);
-
$data = array();
-
foreach ( $json->trends as $trends )
-
{
-
foreach ($trends as $val)
-
-
echo "<a href='http://search.twitter.com/search?q=" . urlencode("{$val->query}") . "'>{$val->name}</a> ";
-
//array_push($data, "{$val->query}","{$val->name}");
-
-
$data["name"] = "{$val->name}";
-
$data["query"] = "{$val->query}";
-
}
-
The echo statement works perfectly. The array in the assignment statements ends up with only the final two key-value pairs. I also tried an array_push (which is commented out) to assign the values, with the same results.
The data I want from the json object is fairly deep. All I want to get at is the [name] and [query] values. Here is the output of a print_r for the original $json object: -
stdClass Object
-
(
-
[trends] => stdClass Object
-
(
-
[2009-12-03 21:10:18] => Array
-
(
-
[0] => stdClass Object
-
(
-
[name] => #whoiam
-
[query] => #whoiam
-
)
-
-
[1] => stdClass Object
-
(
-
[name] => #thingsilove
-
[query] => #thingsilove
-
)
-
-
[2] => stdClass Object
-
(
-
[name] => Tiger Woods
-
[query] => "Tiger Woods"
-
)
-
-
[3] => stdClass Object
-
(
-
[name] => Pleasure P
-
[query] => "Pleasure P"
-
)
-
-
[4] => stdClass Object
-
(
-
[name] => Christmas
-
[query] => Christmas
-
)
-
-
[5] => stdClass Object
-
(
-
[name] => New Moon
-
[query] => "New Moon"
-
)
-
-
[6] => stdClass Object
-
(
-
[name] => #seenewmoonagain
-
[query] => #seenewmoonagain
-
)
-
-
[7] => stdClass Object
-
(
-
[name] => Grammy
-
[query] => Grammy
-
)
-
-
[8] => stdClass Object
-
(
-
[name] => Holiday
-
[query] => Holiday
-
)
-
-
[9] => stdClass Object
-
(
-
[name] => Santa
-
[query] => Santa
-
)
-
-
)
-
-
)
-
-
[as_of] => 1259874618
-
)
-
What am I missing here?
Thanks for the help,
Jon Meek
0 2486 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andy Fish |
last post by:
Hi,
I have a webpage with some javascript that constructs some data structures,
some of which contain nested structures or arrays of other structures. It's
the same order of complexity as a web.xml file, say.
I need to post the whole lot to the server and I'm not sure which is the
best way to do it. It has to be browser-independent. The only ways I can
think of are:
|
by: Pavils Jurjans |
last post by:
Hello,
I have a fairly complex project with server-side written in C# (.NET),
and client-side heavily relying on the presence on
JavaScript-compatible scripting engine. One of the features thie
project utilizes is "virtual POST", ie, client side submits the data
to the server side, using Microsoft.XMLHTTP ActiveX Object (in MSIE),
or XMLHttpRequest class in Mozilla, and when the server returns reply,
processes it in client side to run...
|
by: Luke Matuszewski |
last post by:
Welcome
As suggested i looked into JSON project and was amazed but...
What about cyclical data structures - anybody was faced it in some
project ?
Is there any satisactional recomendation...
PS i am ready to use JSON as data/object interchange when using AJAX
and my J2EE project - because it is easier to traverse the JavaScript
object than its XML representation (so of course may argue).
|
by: Noozer |
last post by:
I've been doing some reading about "AJAX" and it sounds pretty interesting.
While I can make it work, it seem like I'm doing much of it the "hard way".
I was wondering what kind of code that others use to pass data via
XMLHTTPRequest.
My code is usually in ASP, with VBScript or Javascript for the client side
of things. I've done a bit of PHP as well. Definately not an expert by any
means, but I do understand programming - I just don't...
|
by: Kevin Newman |
last post by:
Hello,
I noticed that the JavaScript library for JSON posted on json.org
(http://www.json.org/json.js) is modifying Object.prototype (adding a
method - toJSONString). I thought this was considered bad practice
because it can disrupt the use of for in loops on Objects.
Am I incorrect?
Thanks,
| |
by: Red Daly |
last post by:
Hello group,
I have been using JSON for a while and it has made many things a breeze.
However, JSON does not natively describe certain things like pointers
and custom types. I created a simple JSON extension that allows
cross-references, and I'm asking for your thoughts on a simple type system.
I've dubbed this variation RJSON (Red's JSON) for lack of a shorter
name. Here's how it works right now:
|
by: ChrisO |
last post by:
I've been pretty infatuated with JSON for some time now since
"discovering" it a while back. (It's been there all along in
JavaScript, but it was just never "noticed" or used by most until
recently -- or maybe I should just speak for myself.)
The fact that JSON is more elegant goes without saying, yet I can't
seem to find a way to use JSON the way I *really* want to use it: to
create objects that can be instantated into multiple...
|
by: Jasper |
last post by:
Hi, Maybe this is off-topic, but perhaps you can help. I'm looking for ideas
on how to parse a data file.
I dont know XML but I know it parses data in text format.
I have a structured data file of the general form shown below. I dont have
any definition of the data. Basically it looks like it is hierarchical,
token/data pairs defined by brackets and square brackets.
I would like to parse this out into some sort of data object(s) in...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |