|
Niko Bromberg
Registered User
Join date: 30 May 2008
Posts: 14
|
09-15-2008 02:37
Help Comrades! I have written a llHttpRequest which is calls information from a database. This works and provides a response, however it is as a message displaying all parameters, which looks messy. Does anyone know/or have any idea how to represent the returned values in a better way? Heres the script so far key http_request_id; default { state_entry() { http_request_id = llHTTPRequest("URL", [HTTP_METHOD, "GET"], ""  ; } http_response(key request_id, integer status, list metadata, string body) { //Make sure the httpd_id is correct! if ( request_id == http_request_id ) { llInstantMessage ( llGetOwner(), "hello\n" + body ); } } } Thanks
|
|
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
|
09-15-2008 03:00
It entirely depends on the structure of the data you get in your HTTP response. Whenever I'm fetching data from outside, the general format I follow is like this blah|blah|blah foo|foo|foo
Each related group of data is on the same line, and individual fields or items are separated by the vertical bar (or pipe) character |.
You would then process it something like this (although be warned it does require quite a bit of memory!):
// Split the data into lines list lines = llParseString2List(body, ["\n"], []); integer numlines = llGetListLength(lines); list fields = []; integer numfields = 0;
// Go through each line integer i = 0; for (i = 0; i < numlines; i++) { // Split the data into fields fields = llParseStringKeepNulls( llList2String(lines, i), ["|"], []); numfields = llGetListLength(numfields);
// Process the data //..... }
That lets you access each field on each line.
|