小编Hug*_*ois的帖子

在转换为float时处理null值

我正在使用Highcharts进行项目.

一点php文件:

$sql    =   "SELECT unix_timestamp(`datetime`) as `datetime`, `temp_cellule`, `temp_exterieur` FROM `tablebase`";
$result =   mysql_query($sql);
$data   =   array();
while   ($row   =   mysql_fetch_array($result)) {
    extract($row);
    $datetime   +=  3600;   //GMT+1
    $datetime   *=  1000;   //UNIX_TIMESTAMP to java
    $data[] =   array((float)$datetime,(float)$temp_cellule);           
    $data2[]=   array((float)$datetime,(float)$temp_exterieur);
}

$array[]    =   json_encode($data);
$array2[]   =   json_encode($data2);
Run Code Online (Sandbox Code Playgroud)

使用此代码: $data2[]= array((float)$datetime,(float)$temp_cellule);

我得到一个好的格式,但Highcharts不识别值"null",因为它不是一个浮点数,所以它被转换为0:

[[1362133360000,25],[1362136955000,0],[1362140579000,35]
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用:( $data[] = array($datetime,$temp_cellule); 没有转换为浮动)我得到"datetime"和"null"的良好格式,但不是因为""因为temp_cellule :

[[1362133360000,"25"],[1362136955000,null],[1362140579000,"35"]]
Run Code Online (Sandbox Code Playgroud)

而且我要:

[[1362133360000,25],[1362136955000,null],[1362140579000,35]]
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

php arrays json encode highcharts

2
推荐指数
1
解决办法
3820
查看次数

简单的递归示例 - 请帮助我理解递归

    public static int triple(int n)
    {
        if (n == 0)
            return 0;
        else
            total = 3 + triple(n-1);
    System.out.println(total);
    return total;
    }
Run Code Online (Sandbox Code Playgroud)

好的,所以我有一个简单的回忆示例,我似乎无法掌握,我希望有人能够让我逐步了解程序如何获得其输出.

这就是我认为会发生的事情.让我们说,n=5 所以程序循环和命中total = 3 + triple(5-1) 我认为将等于7 ..这是程序打印错误

3
6
9
12
15

所以...然后我认为三重必须在打印总数之前再次运行...我相信它确实如此,但我根本不明白它的总计是如何.

因为它看起来像这样:

3 + triple(4)
       3 + triple(3)
               3 + triple(2)
                       3 + triple(1)
                                =3
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下,因为你我可以很失落!

java math recursion

1
推荐指数
1
解决办法
1万
查看次数

使用属性对标签排序

我有这个HTML

<td colspan="4" class="item"> DERBY LINE, VT 05830<br>
    <label for="" data-sort="16.26">UPS Ground $16.26</label><br>
    <label for="" data-sort="27.57">UPS 3 Day Select&reg; $27.57</label><br>
    <label for="" data-sort="33.87">UPS 2nd Day Air&reg; $33.87</label><br>
    <label for="" data-sort="72.82">UPS Next Day Air $72.82</label><br>
    <label for="" data-sort="7.99">USPS Priority $7.99</label><br>
    <label for="" data-sort="9.61">FEDEX SmartPost&reg; FedEx Delivered Via USPS $9.61</label><br>
    &nbsp;
    <input type="button" name="Button5" id="Button5" onmouseout="this.className='btn'" onmouseover="this.className='btn_over'" onclick="document.shipquote.action='shipquote.asp?action=clean';document.shipquote.submit();" value="Clear" class="btn">
</td>
Run Code Online (Sandbox Code Playgroud)

我需要通过"data-sort"属性对其进行排序,现在我正在使用 这个元素排序器, 但是当我运行脚本时它会返回

<td colspan="4" class="item"> DERBY LINE, VT 05830<br>
    <label for="" data-sort="16.26">UPS Ground $16.26</label><br>
    <label for="" data-sort="27.57">UPS 3 Day Select&reg; …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

1
推荐指数
1
解决办法
314
查看次数

如果width == 200px运行函数

这是一个显示问题jsFiddle

我不确定为什么这不起作用:

if ($('#menu').width() == '200px') {
    alert("what");
}
Run Code Online (Sandbox Code Playgroud)

我希望在动画完成时显示警报.所以我假设我可以说,因为当动画完成时,元素的宽度为200px,它会显示警告.

javascript jquery

1
推荐指数
1
解决办法
115
查看次数

错误:XmlListModel不是类型

我在qml中使用XmlListModel:

xml:

<? xml version="1.0" ?>
<queuelist>
    <queue id="1" name="name" image="image.svg" turn="34" wait="50" />
</queuelist>
Run Code Online (Sandbox Code Playgroud)

XmlListModel

    XmlListModel {
        id: queueModel
        source: "queuelist.xml"
        query: "/queuelist/queue"
        XmlRole {name: id; query: "@id/string()"}
        XmlRole {name: queue; query: "@name/string()"}
        XmlRole {name: image; query: "@image/string()"}
        XmlRole {name: turn; query: "@turn/string()"}
        XmlRole {name: wait; query: "@wait/string()"}
    }
Run Code Online (Sandbox Code Playgroud)

QTCreator错误:

file:///home/(...)/3queue-client-list.qml:42 XmlListModel is not a type

/home/(...)/Qt5.0.1/5.0.1/gcc/bin/qmlscene exited with code 255
Run Code Online (Sandbox Code Playgroud)

qml

1
推荐指数
1
解决办法
1762
查看次数

用Cucumber截取屏幕截图

我只是学习如何使用黄瓜.你能告诉我如何完成这段代码吗?

您可以使用以下代码段实现未定义步骤的步骤定义:

Then /^I take a screenshot$/ do
    pending # express the regexp above with the code you wish you had
end
Run Code Online (Sandbox Code Playgroud)

cucumber cucumber-jvm cucumber-junit cucumber-cpp

1
推荐指数
1
解决办法
2万
查看次数

尝试修复NetworkOnMainThreadException但给出Toast错误

我正在尝试为java代码极客中的一个首选示例修复Thread错误.

这是代码:

public class JsonParsingActivity extends Activity {

        String url = "http://search.twitter.com/search.json?q=javacodegeeks";

        @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            new RetreiveFeedTask().execute(url);

        }
    }
Run Code Online (Sandbox Code Playgroud)

RetrieveFeedTask:

public class RetreiveFeedTask extends
        AsyncTask<String, Void, JsonParsingActivity> {

    private Exception exception;
    String url = "http://search.twitter.com/search.json?q=javacodegeeks";

    protected JsonParsingActivity doInBackground(String... urls) {
        try {

            InputStream source = retrieveStream(url);

            Gson gson = new Gson();

            Reader reader = new InputStreamReader(source);

            SearchResponse response = gson.fromJson(reader, SearchResponse.class);

            // Toast.makeText(this, response.query, Toast.LENGTH_SHORT).show();

            List<Result> results = response.results;

            for (Result result : results) { …
Run Code Online (Sandbox Code Playgroud)

android json gson

1
推荐指数
1
解决办法
261
查看次数

在数组中搜索空槽

我正在尝试搜索数组中的第一个空槽.你parseInt()可以引用这个,或者我会用" stobar[b] == null"吗?

int[] stobar = new int[100];
for(int b = 0; b < stobar.length; b++)
{
    if(stobar[b] == Integer.parseInt(""))
    {
        stobar[b] = row;
        stobar[b+1] = col;
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

java arrays parseint

1
推荐指数
1
解决办法
346
查看次数

如何使用Java中的套接字将文件名与文件一起发送?

我有以下代码通过套接字传输文件.如何发送文件名?

Socket socket = new Socket("localhost", port);//machine name, port number
File file = new File(fileName);
// Get the size of the file
long length = file.length();
if (length > Integer.MAX_VALUE) 
{
    System.out.println("File is too large.");
}
byte[] bytes = new byte[(int) length];
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());

int count;

while ((count = bis.read(bytes)) > 0) 
{
    out.write(bytes, 0, count);
}

out.flush();
out.close();
fis.close();
bis.close();
socket.close();
Run Code Online (Sandbox Code Playgroud)

java sockets p2p

0
推荐指数
1
解决办法
5139
查看次数

如何让.click在jquery中执行两个函数?

我是jQuery和JaVascript的新手,我喜欢它,但我有问题,,,

我有一个名为button1的元素,我希望在单击一次时使另一个名为bubble1的元素消失,再次单击时重新显示.

我尝试了这个,但它没有用

$(document).ready(function(){
    $('#button_1').click(function (){
        $('#bubble1').css('visibility','hidden');
        $('#button_1').click (function(){
            $('#bubble1'.css('visibility'.'visible');
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

第二个工作,但对象消失,只需点击一下即可重新出现.

$(document).ready(function (){
    $('#button_1').click(function (){
        $('#bubble1').fadeOut();
    });
});
$('#button_1').click(function (){
    $('#bubble1').fadeIn();
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery

0
推荐指数
1
解决办法
75
查看次数

如何使用正则表达式从此字符串中获取电子邮件

我有很多带有这种模式的字符串

/ucwa/oauth/v1/applications/101507538841/people/adan.maddox@dc.com/presence

我如何使用正则表达式来获取电子邮件 adan.maddox@dc.com

我尝试了这个代码,它的工作,但我觉得这不是一个好方法.

    var y = myString.substring(0, myString.lastIndexOf("/presence"));
    var email = y.substring(y.lastIndexOf("people/") + 7);
Run Code Online (Sandbox Code Playgroud)

javascript regex

0
推荐指数
1
解决办法
82
查看次数