Browsing 7239 questions and answers with Jon Skeet

Deserialize JSON object structure with ids as keys

I have this JSON that is generated by a third party web service { "user_data": { "123456789": { "transactions_id": 123456789, "transaction_date":...
Jon Skeet
people
quotationmark

This isn't a particularly unusual structure in JSON. That should be deserialized to a Dictionary<string, User>: public class Root { [JsonProperty("user_data")] public Dictionary<string, User> Users { get; set;... more 9/13/2015 6:02:15 PM

people

ObservableDictionary Initialisation

I have implemented an ObservableDictionary (code pasted below). If I initialise the ObservableDictionary using the overloaded ctor public...
Jon Skeet
people
quotationmark

This constructor is the problem: public ObservableDictionary(IDictionary<TKey, TValue> dictionary) { dictionary = new Dictionary<TKey, TValue>(dictionary); } That's assigning a new value to the parameter, rather than to... more 9/12/2015 12:23:40 PM

people

BigDecimal toEngineeringString not working

I would to use toEngineeringString() but it doesn't works : Log.v("smslms",BigDecimal.valueOf(1_000_0000_000_000_000L).toEngineeringString());` output : 09-11 16:26:12.221 ...
Jon Skeet
people
quotationmark

It's behaving exactly as documented: Returns a string that represents the BigDecimal as described in the toString() method, except that if exponential notation is used, the power of ten is adjusted to be a multiple of three... more 9/11/2015 2:42:13 PM

people

Why static constructor not called before first call to class method

According to Jon Skeet's artice C# and beforefieldinit and discussion in When is a static constructor called in C#? static constructor must be called before first call to a method...
Jon Skeet
people
quotationmark

Your call to StaticClass.Equals is actually just a call to Object.Equals(Object, Object), as StaticClass doesn't provide an applicable overload for Equals. If you look in the IL, you'll see that the compiler has resolved the call to just... more 9/11/2015 2:24:06 PM

people

How to find out if a stream complies with the charset encoding ISO 8859 1

I have a problem whereby I need to be able to detect whether a byte array contains characters which comply with ISO-8859-1 encoding. I have found the following question useful...
Jon Skeet
people
quotationmark

I have a problem whereby I need to be able to detect whether a byte array contains characters which comply with ISO-8859-1 encoding. Well every stream of binary data can be viewed as "valid" in ISO-8859-1, as it's simply a... more 9/11/2015 9:52:49 AM

people

How not to get a comma on the output?

NumberFormat df = NumberFormat.getNumberInstance(); df.setMaximumFractionDigits (2); df.setMinimumFractionDigits (2); double[] floatValues = new double[5]; ...
Jon Skeet
people
quotationmark

This is the issue: NumberFormat df = NumberFormat.getNumberInstance(); That's getting the format for your machine's default locale, which presumably uses a comma as the decimal point. Just use the US locale: NumberFormat df =... more 9/11/2015 6:20:17 AM

people

Display chinese character in HTML file

we have one servlet program which is using the HTML code inside the servlet program i.e HTML.append("<html>"); HTML.append(lnTag); HTML.append("<head>"); HTML.append(lnTag); HTML.append("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"); String titalsLang = resourceBundle.getString("eayslip.tan.title"); HTML.append("<title>"+resourceBundle.getString("eayslip.tan.title")+"</title>");</i> // and list of codes... out.print(HTML); response.setContentType("text/html; charset=UTF-8"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); I am getting the Chinese character from the property file while debugging into the code. But once the response is sent to the page, in the html page we are getting question mark ?????. We have no problems with English characters and they are displaying correctly.
Jon Skeet
people
quotationmark

I suspect the problem is that you're setting the content type - including the encoding - after calling HttpServletResponse.getWriter(), assuming that's where out comes from. From the documentation of ServletResponse.setContentType: ... more 9/11/2015 6:11:23 AM

people

SortedList does not remove and adding items correctly

I encountered a problem with SortedList where 2 methods give 2 diffrent results. //Item Data is one of this sortedList item var itemPos = Items.IndexOfValue(ItemData); Item...
Jon Skeet
people
quotationmark

You're confused between the key of the entry and the index of the entry. Your MoveItem method just changes the key associated with a value (by removing the old entry and creating a new entry). After these lines: Items.Add(0,... more 9/10/2015 9:13:53 PM

people

Creating an iterator in Java

I have the following class: public abstract class MapObjects<MapleMapObject> { private Map map; private HashMap<Integer, MapleMapObject> objects; public...
Jon Skeet
people
quotationmark

If you just want to be able to iterate over objects map, you can just call values() on that and then create an iterator from that value set: public abstract class MapObjects<MapleMapObject> implements Iterable<MapleMapObject>... more 9/10/2015 7:23:09 PM

people

Convert list to set by ImmutableSet.copyOf() and new HashSet<>(list);

Good day, I have a set that contains some data: Set< AItem > aItems = aItem .getItems( ); Because I want to do some sorting, so I convert it to list...
Jon Skeet
people
quotationmark

HashSet should be viewed as an unordered set. If you want a sorted set, just use a TreeSet: Set<AItem> sortedItems = new TreeSet<>(new Comparator<AItem>() { ... }); sortedItems.addAll(aItems); (Don't use the raw type... more 9/10/2015 9:19:58 AM

people