null

How to default a null JSON property to an empty array during serialization with a List<T> property in JSON.NET?

回眸只為那壹抹淺笑 提交于 2019-12-18 13:23:28
问题 Currently I have JSON that either comes in via an HTTP call or is stored in a database but during server processing they are mapped to C# objects. These objects have properties like public List<int> MyArray . When the JSON contains MyArray:null I want the resulting property to be an empty List<T> instead of a null List<T> property. The goal is that the object will "reserialize" to JSON as MyArray:[] , thus either saving to the database or responding out via HTTP as an empty array instead of

How to set localstorage item back to null.

♀尐吖头ヾ 提交于 2019-12-18 12:50:51
问题 I'm using a system to alert users when a major update has happened to a site, and I do it with LocalStorage, when I made the system, I made the system check if tip was "null", then set "tip" to true when they got the alert. Now, I would like to set the 'tip' localstorage back to null, and use "tip2" instead. Would I do this? localStorage.setItem('tip', 'null'); 回答1: localStorage.removeItem('tip') if you are aiming to remove the key localStorage.setItem('tip', 'null') if you just want to set

How do I check if there's a nil set or not in an array?

隐身守侯 提交于 2019-12-18 12:47:09
问题 If I set some nil values to an array, I don't seem to be able to check for them. I have tried any? and empty? . array = [nil, nil, nil] #=> [nil, nil, nil] array[1].any? #=> "NoMethodError: undefined method `any?' for nil:NilClass" 回答1: any? iterates over a container, like an array, and looks at each element passed to it to see if it passes a test. If one does, the loop stops and true is returned: ary = [nil, 1] ary.any?{ |e| e.nil? } # => true The documentation explains this well: Passes

why do we use NULL in strtok()?

一曲冷凌霜 提交于 2019-12-18 12:40:11
问题 Why do we use null in strok() function? while(h!=NULL) { h=strtok(NULL,delim); if(hold!=NULL) printf("%s",hold); } What does this program do when *h is pointing to a string? 回答1: strtok is part of the C library and what it does is splitting a C null-delimited string into tokens separated by any delimiter you specify. The first call to strtok must pass the C string to tokenize, and subsequent calls must specify NULL as the first argument, which tells the function to continue tokenizing the

Mysql Left Join Null Result

痴心易碎 提交于 2019-12-18 12:15:23
问题 I have this query SELECT articles.*, users.username AS `user` FROM `articles` LEFT JOIN `users` ON articles.user_id = users.id ORDER BY articles.timestamp Basically it returns the list of articles and the username that the article is associated to. Now if there is no entry in the users table for a particular user id, the users var is NULL. Is there anyway to make it that if its null it returns something like "User Not Found"? or would i have to do this using php? 回答1: Use: SELECT a.*,

How to remove a null value from NSDictionary

折月煮酒 提交于 2019-12-18 11:49:28
问题 I have a JSON Feed: { "count1" = 2; "count2" = 2; idval = 40; level = "<null>"; "logo_url" = "/assets/logos/default_logo_medium.png"; name = "Golf Club"; "role_in_club" = Admin; } The problem is the "<null>" that I cannot figure out how to remove from the NSDictionary before saving it to NSUserDefaults. Please help me solve this issue. Thankyou! 回答1: Iterate through the dictionary and look for any null entries and remove them. NSMutableDictionary *prunedDictionary = [NSMutableDictionary

Assigning NULL to a list element in R?

雨燕双飞 提交于 2019-12-18 10:59:07
问题 I found this behaviour odd and wanted more experienced users to share their thoughts and workarounds. On running the code sample below in R: sampleList <- list() d<- data.frame(x1 = letters[1:10], x2 = 1:10, stringsAsFactors = FALSE) for(i in 1:nrow(d)) { sampleList[[i]] <- d$x1[i] } print(sampleList[[1]]) #[1] "a" print(sampleList[[2]]) #[1] "b" print(sampleList[[3]]) #[1] "c" print(length(sampleList)) #[1] 10 sampleList[[2]] <- NULL print(length(sampleList)) #[1] 9 print(sampleList[[2]]) #

Why does this string extension method not throw an exception?

痴心易碎 提交于 2019-12-18 10:09:37
问题 I've got a C# string extension method that should return an IEnumerable<int> of all the indexes of a substring within a string. It works perfectly for its intended purpose and the expected results are returned (as proven by one of my tests, although not the one below), but another unit test has discovered a problem with it: it can't handle null arguments. Here's the extension method I'm testing: public static IEnumerable<int> AllIndexesOf(this string str, string searchText) { if (searchText =

Check if AJAX response data is empty/blank/null/undefined/0

≯℡__Kan透↙ 提交于 2019-12-18 10:03:36
问题 What I have: I have jQuery AJAX function that returns HTML after querying a database. Depending on the result of the query, the function will either return HTML code or nothing (i.e. blank) as desired. What I need: I need to conditionally check for when the data is blank. My code: $.ajax({ type:"POST", url: "<?php echo admin_url('admin-ajax.php'); ?>", data: associated_buildsorprojects_form, success:function(data){ if(!data){ //if(data="undefined"){ //if(data==="undefined"){ //if(data==null){

How to fill nan value with the previous available in the row?

末鹿安然 提交于 2019-12-18 09:32:58
问题 I need to fill the nan value in a dataframe by using the previous available value in a row, as the data are timeseries. Here there is an example: 1 2 3 4 b b nan c c nan d nan d nan nan c What I need is: 1 2 3 4 b b b c c c d d d d d c I know the method fillna from panda, but the methods are only based on columns. I think about doing a transposition and after the use of the fillna method, but I would like to know if there are more efficient way to do that. 回答1: Use ffill along the first axis.