2012-09-16, 02:31
(2012-09-16, 02:01)Mizaki Wrote: I've never had to do it that way. Have you looked at http://www.w3schools.com/xml/xml_parser.asp etc.?
So does the JSON result return as an XML String?
(2012-09-16, 02:01)Mizaki Wrote: I've never had to do it that way. Have you looked at http://www.w3schools.com/xml/xml_parser.asp etc.?
(2012-09-15, 23:28)Mizaki Wrote: You should get an object back. For example: In the above we should get an object called "result". As you can see from your result there is also a "result". So:will give you "audio" in this case. jQuery will automatically parse it into an object from the JSON.Code:result.result.type
function xbmcjson(command){
var params = '{"jsonrpc": "2.0", "method": "'+ command +'", "id": "1"}';
$.ajax({
type: 'POST',
url: 'http://192.168.1.9:80/jsonrpc',
data: params,
success: function(result, textStatus, XMLHttpRequest) { console.log(result) },
dataType: 'json',
contentType: 'application/json'
});
}
function objToStr(obj, indent) {
var out = '';
for (var e in obj) {
if (typeof obj[e] == 'object') {
out += indent + e + ":\n" + objToStr(obj[e], indent+' ') + "\n";
} else {
out += indent + e + ": " + obj[e] + "\n";
}
}
return out;
};
(2012-09-16, 15:46)Mizaki Wrote: Is that with an alert? Can you console.log? In browsers that'll show you the whole object. Otherwise it'll have to be stringifed. Something like:
Code:function objToStr(obj, indent) {
var out = '';
for (var e in obj) {
if (typeof obj[e] == 'object') {
out += indent + e + ":\n" + objToStr(obj[e], indent+' ') + "\n";
} else {
out += indent + e + ": " + obj[e] + "\n";
}
}
return out;
};
function objToStr(result, indent) {
var out = '';
for (var e in result) {
if (typeof result[e] == 'object') {
out += indent + e + ":\n" + objToStr(result[e], indent+' ') + "\n";
} else {
out += indent + e + ": " + result[e] + "\n";
}
}
return out;
};
objToStr(result, 1);
(2012-09-16, 16:25)Mizaki Wrote: Add that function then call it with "result". Never actually used it. MKay used it. I guess try:
Code:objToStr(result, 1);
Might have to play around or google for another object to string function.
function xbmcjson(command){
var params = '{"jsonrpc": "2.0", "method": "'+ command +'", "id": "1"}';
$.ajax({
type: 'POST',
url: 'http://192.168.1.9:80/jsonrpc',
data: params,
success: function(result, textStatus, XMLHttpRequest){ JSON.stringify(result) },
dataType: 'json',
contentType: 'application/json'
});
}
(2012-09-19, 16:02)Montellese Wrote: You need to URL encode the whole image:// path (including "image://") that you get from JSON-RPC and append that to the image handler i.e. http://192.168.1.9:80/image/
(2012-09-19, 21:30)Montellese Wrote: Yes if you URL encoded the image:// path you can download/view the image in a browser.
image://music@smb%3a%2f%2fDOE-HTPC%2fStorage%20(E)%2fMusic%2fOasis%20-%20Hello.mp3
http://192.168.1.9:80/image/image%3A%2F%2Fmusic%40smb%253a%252f%252fDOE-HTPC%252fStorage%2520(E)%252fMusic%252fOasis%2520-%2520Hello.mp3
http://192.168.1.9:80/image/image%253A%252F%252Fmusic%2540smb%25253a%25252f%25252fDOE-HTPC%25252fStorage%252520%28E%29%25252fMusic%25252fOasis%252520-%252520Hello.mp3