I need to transform one document formated in xml into JSON and vice versa.
I belive this is a common requirement and perhaps there's still one library that does that work.
Know any?
var response = "{\"tree\":[{\"level1\":[{\"node\":{\"id\": 1,\"name\": \"paradox\",\"parent\": 0}}]},{\"level2\":[{\"node\":{\"id\": 2,\"name\": \"lucent\",\"parent\": 1}},{\"node\":{\"id\": 3,\"name\": \"reiso\",\"parent\": 1}}]},{\"level3\":[{\"node\":{\"id\": 4,\"name\": \"pessi\",\"parent\": 3}},{\"node\":{\"id\": 5,\"name\": \"misho\",\"parent\": 2}}]},{\"level4\":[{\"node\":{\"id\": 6,\"name\": \"hema\",\"parent\": 5}},{\"node\":{\"id\": 7,\"name\": \"iiyo\",\"parent\": 4}}]}]}";
var data = eval("(" + response + ")");
This is a dummy json response I am currently testing. Now how do I get the value of "name" in the 1st node of "level1" from the "tree"? Thanks
I have a string in my db I want to pull into my page and convert to a json object.
[
{id: 1,title: "Long Event",
start: new Date(2009, 5, 6, 14, 0),end: new Date(2009, 5, 11)},
{id: 2,title: "Repeating Event",
start: new Date(2009, 5, 2)},
{id: 3,title: "Meeting",
start: new Date(2009, 5, 20, 9, 0)},
{id: 4,title: "Click for Facebook",
start: new Date(2009, 5, 27, 16),end: new Date(2009, 5, 29),
url: "http://facebook.com/"}
]
How can I do this using JQuery?
Can someone help me understand how to create a JSON object like: [{"locationID":"16","locationDesc":"XXXX"}, {"locationID":"111","locationDesc":"XXXX"}, {"locationID":"12","locationDesc":"XXXX"}, {"locationID":"11","locationDesc":"XXXX"}]
I'd like to build this object via a LOOP, so some way to append over and over.
thxs
Although iPhone support JSON natively, and easy to consume RESTful services, AMF is a binary protocol and it supposes to use much less bandwidth. Do you think using AMF + Flash remoting is a good idea?
Just found this AMF library in cocoa (Objective-C): http://github.com/nesium/cocoa-amf/
I would like to pass
{"parameter1":true, "parameter2":false, "parameter3":true}
To my action
public JsonResult Action(bool parameter1, bool parameter2, bool parameter3)
{
//...
}
Using JQueries ajax method using the JSON as the data parameter (data: {"parameter1...)
How do I accomplish this, right now my parameters aren't getting recognized on the server side.
If I have a block of code like this:
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
end
How do I add something like
format.json
Any tips, pointers, ideas gladly welcomed...
Hi there,
I'm loosing my hair trying to figure out why net.sf.json.JSONObject add extra backslash where it shouldn't on my java code :
JSONObject obj = new JSONObject ();
obj.element ("column_name", "<a href=\"#\" title=\"test\">Test !</a>");
will output :
<a href=\"#\" title=\"test\">Test !<\/a>
with an extra "\" near <\/a.
How can I avoid this behavior ?
Thanks for your help !
In Adobe Flex / Actionscript 3, I would love to pretty print my JSON data to a TextArea. Any libraries out there? A decent search turned up no results. Thanks!
I am getting JSON response,now i need to construct a table using this response.The table may be contain more than one record and i know one way of doing this is using Jstl tags but not JSON response.Here is my jsp code
<div id="divHideAllergies" class="clone">
<div class="copy">
<div class="col-md-12">
<div class="portlet box carrot ">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-medkit"></i> Allergies
</div>
</div>
<div class="portlet-body form">
<div class="form-body">
<div class="form-group">
<label class="control-label col-md-3">Allergy Type:</label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-medkit"></i></span>
<select class="form-control" id="allergy_type">
<option selected value="">--Select One--</option>
<option value="Drug">Drug</option>
<option value="Environmental">Environmental</option <option value="Food">Food</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Allergic to:</label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-medkit"></i></span>
<input type="text" class="form-control" name="first name" id="allergy_to"/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
https://search.twitter.com/search.json?q=doug
How do I read this like VIEW SOURCE, so that I know what I'm looking at?
Is there a website that can prettify it for me?
BTW, I use python
My site does some short ajax call in JSON format, using jQuery.
At client-side i'd like to send object just passing it in ajax function, without being forced to wrap it in an object literal like this: {'JSON_Obj' : myJSON_Obj }.
For the same reasons, at server-side i'd like to manage objects without the binding of $_GET['JSON_Obj'] or $_POST['JSON_Obj'].
For example, using file_get_contents("php://input"), i can manage POST requests in that way, but in GET format it doesn't work.
Any suggestions?
I have a JSON Struct like
appointerment= {ids: '15,16,17', appointments: {'15': '12.05.2010,14,05,2010'} }
now in appointments object I want to add something like '16', '21.05.2010'
what is the best possible way to do this.
How can I convert a JSON string to an object in JavaScript? Is there a method that does this?
Something like:
var x = "{ id: 5, name: 'hello' }";
var y = /*something*/(x);
alert(y.id + " " + y.name);
I need to transform one document formated in xml into JSON and vice versa.
I belive this is a common requirement and perhaps there's still one library that does that work.
Know any?
Is there a way to convert it into object form? So that each field of the result can be accessed results[i].field
where i is the number of records in the mysql result..
This is my JSON String
http://pastebin.com/Cky1va3K
What are the benefits of storing XML in SQL Server over storing JSON in a varchar field?
Any tutorial available for how to use the XML data type effectively?
Do I need to provide the dtd / xml schema somehow? I've heard it is optional, right?
Thank you.
hey guys,
i use drew's autoSuggest plugin for some time but up until now I have hard coded my data into my JS, I'm trying to see if I can use AJAX to return the JSON data and query data like that. I seem to have it working but no matter what I try I can't get the results to be shown in the drop down UL it creates via jquery.
The JSON comes back as it should. This is my PHP code:
$input = $_GET["q"];
$data = array();
// query your DataBase here looking for a match to $input
$query = mysql_query("SELECT `state`, `idStates` FROM `states_list` WHERE (`state` LIKE '%{$input}%' OR `abbr` LIKE '%{$input}%')");
while ($row = mysql_fetch_assoc($query)) {
$json = array();
$json['value'] = $row['idStates'];
$json['name'] = $row['state'];
$data[] = $json;
}
header("Content-type: application/json");
echo json_encode($data);
and my JS:
$('#state').autoSuggest('resources/ajax/suggest.php', {matchCase: true, minChars: 2, startText: '', emptyText: '', retrieveComplete: function(data){ console.log(data.value) }});
I have been trying to debug so I added the retrieveComplete parameter in there for that.
the PHP returns the AJAX with the JSON content...now just to figure out how to get the JS to pick it up append it to the UL LI
UPDATE:
I appened the data to a test div and its returning
results:[object Object],[object Object],[object Object]
I am trying to accomplish a "re-load." More specifically, I need to be able to refresh a portion of my page as a result of another successful ajax call.
Moreover, I load my portion of the page via ajax which obtains it's content from an ajax post. The result is my content being displayed inside my portion precisely.
I need this portion of the page refreshed after a successful ajax post.
Here is some of the code:
/* Ajax-- this part is loaded automatically, and I need it reloaded upon
success of another ajax post. This data comes from the outcome
of my other ajax function. */
$('#newCo').load('click', function() {
$.ajax({
url: 'index.php?dkd432k=uBus/310/Indeed',
dataType: 'json',
success: function(json) {
if (json['newCompare']) {
$('#newCo .newResults').html(json['newCompare']);
}
}
});
});
The next portion of code is responsible for posting the data of which I obtain in this above ajax function.
function ZgHiapud (ofWhich) {
$.ajax({
url: 'index.php?dkd432k=uBus/310/update',
type: 'post',
data: 'product_id=' + product_id,
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, .information').remove();
if (json['success']) {
$('.attention').fadeIn('slow');
$('#compare_total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
}
});
}
In the end, I need to obtain the data that I send to the server immediately upon success of the second ajax call. This data that is sent via the second ajax call needs to fire the first ajax call upon success.
I created a JSON using a PHP script.
I am reading the JSON and can see that the data has been correctly read.
However, when it comes to access the objects I get unrecognized selector sent to instance...
Cannot seem to find why that is after too many hours !!!! Any help would be great !
My code looks like that:
`NSDictionary *json = [[NSDictionary alloc] init];
json = [NSJSONSerialization JSONObjectWithData:receivedData options:kNilOptions error:&error];
NSLog(@"raw json = %@,%@",json,error);
NSMutableArray *name = [[NSMutableArray alloc] init];
[name addObjectsFromArray: [json objectForKey:@"name"]];`
The code crashes when reaching the last line above.
The output like this:
raw json = (
{
category = vacancies;
link = "http://blablabla.com";
name = "name 111111";
tagline = "tagline 111111";
},
{
category = vacancies;
link = "http://blobloblo.com";
name = "name 222222222";
tagline = "tagline 222222222";
}
),(null)
2012-06-23 21:46:57.539 Wind expert[4302:15203] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0xdcfb970
HELP !!!
I have a page like this:
<form class="ajax" method="post" action="add_item.php">
[text input] [submit button]
</form>
[list any items the user has in a div here called #items]
When the user clicks the submit button, a function like this is called:
$("form.ajax").live('submit', function(event) {
params = $(this).serialize();
$.post($(this).attr("action"), params, function(data){
json = $.parseJSON(data);
// do stuff based on the json results
if(json.success.action == 'replace'){
$(json.success.container).html(json.success.message);
}
else{
$(json.success.container).prepend(json.success.message);
$(json.success.container).find(".item:first").slideDown();
}
});
event.returnValue = false;
return false;
});
This is supposed to load add_item.php into the #items div, and it works fine in FF, Chrome, Safari, just not IE. In IE (tested 7 and 8) when I click Submit it redirects the page to add_item.php rather than loading it into the #items div.
I tried adding event.preventDefault(); to the end of the function but that didn't work.
Any ideas?