Skip to content

Instantly share code, notes, and snippets.

@otakup0pe
Created December 10, 2011 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otakup0pe/1457112 to your computer and use it in GitHub Desktop.
Save otakup0pe/1457112 to your computer and use it in GitHub Desktop.
osParseJSONNew Example
//c#
//whut
LSL_Types.LSLInteger i = 0;
LSL_Types.LSLString request = "";
LSL_Types.LSLString url = "http://api.twitter.com/1/trends/1.json";
public void default_event_state_entry()
{
doThing();
llSetTimerEvent(3600);
}
public void default_event_touch_start(LSL_Types.LSLInteger j)
{
doThing();
}
public void default_event_timer()
{
doThing();
}
public void default_event_http_response(LSL_Types.LSLString requestid, LSL_Types.LSLInteger status, LSL_Types.list meta, LSL_Types.LSLString body) {
if ( requestid != request ) {
llSay(0, "wierd request");
} else {
//llSay(0, "status " + (LSL_Types.LSLString) status);
if ( status != 200 ) {
llSay(0, "bad status");
} else {
if ( llSubStringIndex(body, "500 Internal Server Error") != -1 ) {
llSay(0, "twitter sucks");
} else {
handleThing(body);
}
}
request = "";
}
}
private void doThing()
{
request = llHTTPRequest(url, new LSL_Types.list(), "");
}
private void handleThing(LSL_Types.LSLString body) {
LSL_Types.LSLString dynamicText = "MoveTo 40, 10; PenColour Red; Font 48; Text twitter trends; PenColour Black; Font 32; ";
//llSay(0, body);
//llSay(0, "retrieved " + (LSL_Types.LSLString) llStringLength(body) + " bytes");
System.Object response = osParseJSONNew(body);
//llSay(0, "response is a " + response.GetType().ToString());
System.Collections.ArrayList response_list = (System.Collections.ArrayList) response;
System.Collections.Hashtable things = (System.Collections.Hashtable) response_list[0];
//llSay(0, "found " + things.Count.ToString() + " things");
//llSay(0, "things[\"trends\"] is a " + things["trends"].GetType().ToString());
System.Collections.ArrayList trends_list = (System.Collections.ArrayList) things["trends"];
//llSay(0, "found " + trends_list.Count.ToString() + " trends");
LSL_Types.LSLInteger n = 0;
LSL_Types.LSLInteger yy = 50;
for ( n = 0 ; n < trends_list.Count ; n ++ ) {
System.Object this_trend_obj = trends_list[n];
//llSay(0, "this_trend #" + (LSL_Types.LSLString) n + " is a " + this_trend_obj.GetType().ToString());
System.Collections.Hashtable this_trend = (System.Collections.Hashtable) this_trend_obj;
System.Object this_name_obj = this_trend["name"];
//llSay(0, "this_name_obj is a " + this_name_obj.GetType().ToString());
System.String this_name = (System.String) this_name_obj;
//llSay(0, "and it's name is " + this_name);
dynamicText += "MoveTo 10, " + (LSL_Types.LSLString) yy + "; Text " + this_name + ";";
yy += 35;
}
osSetDynamicTextureData("", "vector", dynamicText, "width:512,height:512,alpha:255", 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment