Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6056451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:22:39+00:00 2026-05-23T08:22:39+00:00

When I do $.each(result, function(i, n){ alert(key: + i + , Value: + n

  • 0

When I do

$.each(result, function(i, n){
alert("key: " + i + ", Value: " + n );
});

then for each iteration I see

key: 276, Value: {"owners":["he"],"users":["he","m"],"end":"07/06-2011","groups":[],"type":"in"}

How do I access the values of owners, users, end, groups, and type for each iteration?

In Perl would I have done

foreach my $key (keys %result) {
   print $result{$key}{owners};
   print $result{$key}{users};
   ...
}

Update

I get result from JSON like so

$.ajax({
    type: "GET",
    url: "/cgi-bin/ajax.pl",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: { "cwis" : id },
    // ...
    success: function(result){
    if (result.error) {
        alert('result.error: ' + result.error);
    } else {

        $.each(result, function(i, n){
        alert( "key: " + i + ", Value: " + n );

        });


    }
    }
});

Update 2

It seams that the problem is the server side is not sending prober JSON.

This is the server side script that generate the JSON string.

!/usr/bin/perl -T

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use JSON;
use utf8;
use strict;
use warnings;

my $cgi = CGI->new;
$cgi->charset('UTF-8');

my $json_string = qq{{"error" : "The user do not have any activities."}};

my $json = JSON->new->allow_nonref;
$json = $json->utf8;

# @a and $act is now available

my $data;
foreach my $id (@a) {
    $data->{$id} = $json->encode(\%{$act->{$id}});
}
$json_string = to_json($data);


print $cgi->header(-type => "application/json", -charset => "utf-8");
print $json_string;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:22:39+00:00Added an answer on May 23, 2026 at 8:22 am
    document.write(result[key].owners);
    document.write(result[key].users);
    

    UPDATE:

    Apparently my comment on the question was the answer:

    I’m no CGI expert but it looks like
    you are double encoding your data into
    JSON. Once with

    my $json = JSON->new->allow_nonref; $json = $json->utf8; 
    

    and then again with

    $data->{$id} = $json->encode(\%{$act->{$id}}) .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've the following players, each value corresponds to a result in percentage of right
Event.observe(window, 'load', function() { $$('a.tag_links').each(function(s) { //alert(s.parent.parent.id); //How to get id of its parent
directionsService.route (request, function (result, status) { alert(status); if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections (result);
We have several different optimization algorithms that produce a different result for each run.
The following two queries each give the same result: SELECT column FROM table GROUP
SQL Server (2005/2008) Each of the below statements have the same result. Does anyone
I'd like to send an email for each row of a result set using
@search_results = Array.new duplicates = Set.new results.each { |result| @search_results.push(result) unless duplicates.add?(result[:url]) } This
$(function () { $('#form4').submit(function () { var val = $(#txtNewServiceTypeCategory).val(); $(#ServiceTypeCategoryName).children(option).each(function () { var
Further to this question , I'm getting a curious result when binding a function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.