我是Go的新手,无法弄清楚如何打印出我创建的JSON.我正在使用"encoding/json"并且返回了一个[]字节.然而,当我打印出来时,我得到:
cannot use json_msg (type []byte) as type string in function argument
Run Code Online (Sandbox Code Playgroud)
收到此消息后,我试图将[]字节数组转换为字符串或空接口.但是我似乎无法让它发挥作用.有任何想法吗?相关代码如下:
type Message struct {
Id int
Name string
}
for _, row := range rows {
m := Message{row.Int(0), row.Str(1)}
json_msg, err := json.Marshal(m)
if err == nil {
panic(err)
}//if
//tried below to print out a interface, didn't work either
//var f interface{}
//err = json.Unmarshal(json_msg, &f)
fmt.Fprintf(c.ResponseWriter, json_msg)
}//for
Run Code Online (Sandbox Code Playgroud) 标题几乎说明了一切,我正在尝试从Perl程序运行java程序(.jar文件).我在Stackoverflow上读了另一篇文章说这个语法是正确的:
system("java filename.jar");
Run Code Online (Sandbox Code Playgroud)
但是,这给了我以下错误.我不确定问题是它显示文件名为"filename/jar"而不是"filename.jar"
Exception in thread "main" java.lang.NoClassDefFoundError: filename/jar
Caused by: java.lang.ClassNotFoundException: filename.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Run Code Online (Sandbox Code Playgroud) 我最近通过WHM面板(Web Host Manager)在我们的服务器上安装了PHP APC.安装成功后,我觉得一切都很好.然而第二天我注意到我们的error_log文件变得非常大,经过检查我多次注意到以下行:
PHP警告:PHP启动:无法加载动态库'/usr/local/lib/php/extensions/no-debug-non-zts-20060613/apc.so' - /usr/local/lib/php/extensions/no -debug-non-zts-20060613/apc.so:无法打开共享对象文件:第0行的"未知"中没有此类文件或目录
查看目录我没有看到apc.so,但我也没有看到它在我们的服务器上的任何其他地方(也许它是,我只是没有找到它).无论如何,我可以生成此文件放入正确的文件夹?这会工作,还是我需要重新安装某些东西或更改某个文件中的路径?
所以我最近想通过一个Perl程序来提高速度.收集网站列表,我想为每个网址启动一个帖子并获取每个网站的内容,然后在页面上查找公司描述.一旦一个线程找到了结果,或者所有线程都没有,我想退出,写下我的结果,并在我的下一个公司的URL中读取.
我看到的问题是我在创建线程时使用的函数内部使用Perl :: Unsafe :: Signals模块.我需要不安全的信号来中断被"卡住"的正则表达式.然而,这似乎会导致各种问题,主要是程序崩溃并显示错误信息"闹钟".
因此,有没有办法安全地使用Perl :: Unsafe :: Signals和线程?有没有办法通过向函数发送信号以另一种方式超时正则表达式(就像我在下面发送'KILL'信号?)谢谢.
注意:我将代码删除到所有相关部分,如果您需要更多,请告诉我.
use threads ('exit' => 'threads_only');
use threads::shared;
my @descrip;
share(@descrip);
my $lock;
share($lock);
URL:foreach my $url(@unique_urls) {
#skip blank urls
if(!$url) { next URL; }#if
#find description
my $thread = threads->create(\&findCompanyDescription, $PREV_COMPANY, $PREV_BASE_URL, $url);
#while a description has not been found and there are still active threads, keep looking
#there may be a better way to do this, but this seems to work for me
while(!@descrip && threads->list() …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Java项目,我在下面的TextAnalyzer类中有getter方法:
public Hashtable<String, Double> getTotalFeatureOccurances() {
return(feat_occur_total);
}//getTotalFeatureOccurances
Run Code Online (Sandbox Code Playgroud)
我也有私有类变量:
private Hashtable<String, Double> feat_occur_total;
Run Code Online (Sandbox Code Playgroud)
我使用getter,在hash中添加更多的术语,然后想再次获取hash,但它总是返回空.更糟糕的是,如果我不从哈希中添加或删除任何内容,但是做了两次获取,我仍然会第二次收到并清空哈希值.
这是我的主要代码:
TextAnalyzer ta = new TextAnalyzer();
feat_occur_cat = ta.wordOccurancesCount(text, features);
feat_occur_total = ta.getTotalFeatureOccurances();
Enumeration<Double> e = feat_occur_total.elements();
while(e.hasMoreElements()) {
System.out.println(e.nextElement());
}//while
feat_occur_total.clear();
feat_occur_total = ta.getTotalFeatureOccurances();
e = feat_occur_total.elements();
System.out.println("\n\nSECOND GET\n\n");
while(e.hasMoreElements()) {
System.out.println(e.nextElement());
}//while
Run Code Online (Sandbox Code Playgroud)
我得到输出:
2.0
1.0
5.0
1.0
1.0
3.0
2.0
3.0
SECOND GET
Run Code Online (Sandbox Code Playgroud)
这是整个班级:
public class TextAnalyzer {
TextAnalyzer() {
this.feat_occur_total = new Hashtable<String, Double>();
}
public String[][] wordOccurancesCount(String text, Vector<String> features) {
String[][] …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过Google Charts API实现带注释的时间线图表.我成功地使用AJAX调用从数据库加载数据,但是我注意到虽然注释显示在右侧,但它们不会出现在图形上的点之上(如工具提示).然而,他们工作得很好,我可以点击它们甚至正确包含Annotation过滤器.
在一两个小时左右没有看到任何错误后,我决定回到绘图板并从Google API中获取图表示例代码的精确副本并进行测试.事实证明我遇到了同样的问题.
本教程的链接在这里(注意A和B如何显示在图表本身上),我还粘贴了下面的代码.
是否有一些我缺少的设置或阻止这种情况的东西?我在Chrome和Firefox中测试过,但都没有用.它也适用于我的教程页面,所以我很茫然.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Google Charts Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages':['annotatedtimeline']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Sold Pencils');
data.addColumn('string', 'title1');
data.addColumn('string', 'text1');
data.addColumn('number', 'Sold Pens');
data.addColumn('string', 'title2');
data.addColumn('string', 'text2');
data.addRows([
[new Date(2008, 1 ,1), 30000, undefined, undefined, 40645, undefined, undefined],
[new Date(2008, 1 ,2), 14045, undefined, undefined, 20374, undefined, undefined],
[new Date(2008, 1 ,3), 55022, …Run Code Online (Sandbox Code Playgroud) 我有,我认为/希望,这是一个非常简单的PHP问题.我创建了一个类来创建数据库连接并发出常见查询.我试图通过从同一个数据库类创建两个对象来打开两个不同的数据库连接.我的代码如下:
//connect to DB
$dbh = new DB('localhost', 'db1', 'user', 'pass');
//check connection
if(!$dbh->getStatus()) {
echo($dbh->getErrorMsg());
die;
}//if
//connect to DB 2
$dbh2 = new DB('localhost', 'db2', 'user', 'pass');
//check connection
if(!$dbh2->getStatus()) {
echo($dbh2->getErrorMsg());
die;
}//if
Run Code Online (Sandbox Code Playgroud)
但是,当我调用$ dbh的方法来查询数据库时,它会尝试使用$ dbh2的凭据进行查询.
我的DB构造函数如下:
class DB {
function __construct($host, $db, $user, $pass) {
$dbh = mysql_connect($host, $user, $pass);
mysql_select_db($db, $dbh);
if(!$dbh) {
$this->status = false;
$this->error_msg = 'Error connecting to database: '.mysql_error();
return(false);
}//if
$this->dbh = $dbh;
$this->resetStatusAndErrors();
return($dbh);
}//_construct
Run Code Online (Sandbox Code Playgroud) 我正在尝试将多个值从 PHP 传递到我的 javascript 函数中。该功能现在很简单,只是尝试显示一个带有值的弹出窗口:
<script type="text/javascript">
function showMapsInfo(name, ctr) {
alert('Info = '+name +' '+ctr);
}//function showMapsInfo
</script>
Run Code Online (Sandbox Code Playgroud)
当我只传递一个值、名称或 ctr 时,它工作得很好。但是,当传入两个或多个值时,不会发生警报。这不起作用有什么原因吗?我猜如果这是不可能的,我将不得不使用 AJAX 来完成工作?
这是相关的PHP代码。我在页面上制作多个表单,每个 id 通过 ctr 都是唯一的。我从数据库中读取了 $maps_name 。我可以很好地输出到屏幕,所以没有问题。
echo('<button type="button" id="button'.$ctr.'" onClick="showMapsInfo('.$maps_name.', '.$ctr.');"><img src="img/maps_logo.gif"></button><br/>');
Run Code Online (Sandbox Code Playgroud) 我有一张表看起来像:
id_primary, id_user, amount, date
Run Code Online (Sandbox Code Playgroud)
如果我的条目如下:
1, 1, 5, 2012-01-05
2, 1, 8, 2012-01-15
3, 1, 17, 2012-03-30
4, 2, 3, 2012-01-18
5, 2, 9.5, 2012-01-31
Run Code Online (Sandbox Code Playgroud)
我已经尝试了多个查询来获取每个id_user的最新结果(按时间顺序排列),但无论如何我似乎都可以获得第一行.例如,我希望从这个示例表中得到的是:
3, 1, 17, 2012-03-30
5, 2, 9.5, 2012-01-31
Run Code Online (Sandbox Code Playgroud)
我最近的尝试是这样的:
SELECT a.* FROM table a GROUP BY a.id_user HAVING MAX(a.date)
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?我是否需要以某种方式使用嵌套查询?