use proper JSON encoding/decoding

This commit is contained in:
Graham Knop 2009-02-10 21:41:36 +00:00
parent 7023683b48
commit bf9bd2f0d2
18 changed files with 54 additions and 54 deletions

View file

@ -573,7 +573,7 @@ sub www_editBadgeGroup {
my ($form, $db) = $self->session->quick(qw(form db));
my $f = WebGUI::HTMLForm->new($self->session, action=>$self->getUrl);
my $badgeGroup = $db->getRow("EMSBadgeGroup","badgeGroupId",$form->get('badgeGroupId'));
$badgeGroup->{badgeList} = ($badgeGroup->{badgeList} ne "") ? JSON::decode_json($badgeGroup->{badgeList}) : [];
$badgeGroup->{badgeList} = ($badgeGroup->{badgeList} ne "") ? JSON::from_json($badgeGroup->{badgeList}) : [];
my $i18n = WebGUI::International->new($self->session, "Asset_EventManagementSystem");
$f->hidden(name=>'func', value=>'editBadgeGroupSave');
$f->hidden(name=>'badgeGroupId', value=>$form->get('badgeGroupId'));
@ -842,7 +842,7 @@ sub www_getBadgesAsJson {
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
#-------------------------------------------------------------------
@ -974,7 +974,7 @@ sub www_getRegistrantAsJson {
$badgeInfo->{ribbons} = \@ribbons;
# build json datasource
return JSON->new->utf8->encode($badgeInfo);
return JSON->new->encode($badgeInfo);
}
#-------------------------------------------------------------------
@ -1038,7 +1038,7 @@ sub www_getRegistrantsAsJson {
# build json datasource
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
@ -1073,7 +1073,7 @@ sub www_getRibbonsAsJson {
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
@ -1184,7 +1184,7 @@ className='WebGUI::Asset::Sku::EMSTicket' and state='published' and revisionDate
my $description = $ticket->get('description');
my $data = $ticket->get('eventMetaData');
$data = '{}' if ($data eq "");
my $meta = JSON->new->utf8->decode($data);
my $meta = JSON->new->decode($data);
foreach my $field (@{$self->getEventMetaFields}) {
my $label = $field->{label};
if ($field->{visible} && $meta->{$label} ne "") {
@ -1228,7 +1228,7 @@ className='WebGUI::Asset::Sku::EMSTicket' and state='published' and revisionDate
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
@ -1263,7 +1263,7 @@ sub www_getTokensAsJson {
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
return JSON->new->utf8->encode(\%results);
return JSON->new->encode(\%results);
}
#-------------------------------------------------------------------

View file

@ -987,7 +987,7 @@ assetData.revisionDate
my $jsonOutput;
$jsonOutput->{ResultSet} = {Result=>\@results};
my $encodedOutput = JSON->new->utf8->encode($jsonOutput);
my $encodedOutput = JSON->new->encode($jsonOutput);
return $encodedOutput;
}
@ -1090,7 +1090,7 @@ sub www_getCompareListData {
$session->http->setMimeType("application/json");
return JSON->new->utf8->encode($jsonOutput);
return JSON->new->encode($jsonOutput);
}
#-------------------------------------------------------------------

View file

@ -1517,7 +1517,7 @@ sub www_deleteThingDataViaAjax {
unless ($thingId && $thingDataId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't get thing data without a thingId and a thingDataId."});
return JSON->new->encode({message => "Can't get thing data without a thingId and a thingDataId."});
}
my $thingProperties = $self->getThing($thingId);
@ -1528,11 +1528,11 @@ sub www_deleteThingDataViaAjax {
$self->deleteThingData($thingId,$thingDataId);
$session->http->setMimeType("application/json");
return JSON->new->utf8->encode({message => "Data with thingDataId $thingDataId was deleted."});
return JSON->new->encode({message => "Data with thingDataId $thingDataId was deleted."});
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you specified can not be found."});
return JSON->new->encode({message => "The thingId you specified can not be found."});
}
}
@ -2455,7 +2455,7 @@ sub www_editThingDataSaveViaAjax {
unless ($thingId && $thingDataId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't get thing data without a thingId and a thingDataId."});
return JSON->new->encode({message => "Can't get thing data without a thingId and a thingDataId."});
}
my $thingProperties = $self->getThing($thingId);
@ -2467,19 +2467,19 @@ sub www_editThingDataSaveViaAjax {
if($thingDataId eq 'new' && $self->hasEnteredMaxPerUser($thingId)){
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => $i18n->get("has entered max per user message")});
return JSON->new->encode({message => $i18n->get("has entered max per user message")});
}
my ($newThingDataId,$errors) = $self->editThingDataSave($thingId,$thingDataId);
if ($errors){
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode($errors);
return JSON->new->encode($errors);
}
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you requested can not be found."});
return JSON->new->encode({message => "The thingId you requested can not be found."});
}
}
@ -2568,7 +2568,7 @@ sub www_getThingViaAjax {
unless ($thingId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't return thing properties without a thingId."});
return JSON->new->encode({message => "Can't return thing properties without a thingId."});
}
my $thingProperties = $self->getThing($thingId);
@ -2586,11 +2586,11 @@ sub www_getThingViaAjax {
$thingProperties->{field_loop} = \@field_loop;
$session->http->setMimeType("application/json");
return JSON->new->utf8->encode($thingProperties);
return JSON->new->encode($thingProperties);
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you requested can not be found."});
return JSON->new->encode({message => "The thingId you requested can not be found."});
}
}
@ -2620,11 +2620,11 @@ sub www_getThingsViaAjax {
}
}
if (scalar @visibleThings > 0){
return JSON->new->utf8->encode(\@visibleThings);
return JSON->new->encode(\@visibleThings);
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "No visible Things were found in this Thingy."});
return JSON->new->encode({message => "No visible Things were found in this Thingy."});
}
}
@ -2982,7 +2982,7 @@ sub www_searchViaAjax {
unless ($thingId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't perform search without a thingId."});
return JSON->new->encode({message => "Can't perform search without a thingId."});
}
if ($thingProperties->{thingId}){
@ -2993,11 +2993,11 @@ sub www_searchViaAjax {
my $var = $self->getSearchTemplateVars($thingId,$thingProperties);
$session->http->setMimeType("application/json");
return JSON->new->utf8->encode($var);
return JSON->new->encode($var);
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you requested can not be found."});
return JSON->new->encode({message => "The thingId you requested can not be found."});
}
}
@ -3393,7 +3393,7 @@ sub www_viewThingDataViaAjax {
unless ($thingId && $thingDataId) {
$session->http->setStatus("400", "Bad Request");
return JSON->new->utf8->encode({message => "Can't get thing data without a thingId and a thingDataId."});
return JSON->new->encode({message => "Can't get thing data without a thingId and a thingDataId."});
}
my $thingProperties = $self->getThing($thingId);
@ -3404,16 +3404,16 @@ sub www_viewThingDataViaAjax {
my $output = $self->getViewThingVars($thingId,$thingDataId);
if ($output){
return JSON->new->utf8->encode($output);
return JSON->new->encode($output);
}
else{
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingDataId you requested can not be found."});
return JSON->new->encode({message => "The thingDataId you requested can not be found."});
}
}
else {
$session->http->setStatus("404", "Not Found");
return JSON->new->utf8->encode({message => "The thingId you requested can not be found."});
return JSON->new->encode({message => "The thingId you requested can not be found."});
}
}