开发者

java reading numbers, interpreting as octal, want interpreted as string

开发者 https://www.devze.com 2022-12-29 13:34 出处:网络
i am having an issue, where java is reading an array list from a YAML file of numbers, or strings, and it is interpreting the numbers as octal if it has a leading 0, and no 8-9 digit.

i am having an issue, where java is reading an array list from a YAML file of numbers, or strings, and it is interpreting the numbers as octal if it has a leading 0, and no 8-9 digit.

is there a way to force java to read the yaml field as a string?

code:

ArrayList recordrarray = (ArrayList) sect.get("recordnum");
   if (recordrarray != null) {
      recno = join (recordrarray, " ");
   }

HAVE ALSO TRIED:

Iterator<String> iter = recordrarray.iterator();
       if (iter.hasNext()) recno = " " +String.valueOf(iter.next());
       System.out.println(" this recnum:" + recno);
       while (iter.hasNext()){
          recno += ""+String.valueOf(iter.next()));

        System.out.println(" done recnum:" + String.valueOf(iter.next()));

       }

the input is such: 061456 changes to 25390 061506 changes to 25414 061559 -> FINE

it took a while to figure out what it was doing, and apparently this is a common issue for java,

ideas? thanks

edit: using jvyaml

yaml:

  22:
country_code: ' '
description: ''
insection: 1
recordnum:
  - 061264
type: misc

yaml loading:

import org.jvyaml.YAML;
Map structure = new Ha开发者_运维知识库shMap();
structure = (Map) YAML.load(new FileReader(structurefn)); // load the structure file


Where are you reading the file? The problem lies in where the file contents are being read. Most likeley the recordarray list contains integers, ie. they have alreadey been parsed. Find the place where the records are being read. Maybe you are doing something like this:

int val = Integer.parseInt(record);

Use this instead:

int val = Integer.parseInt(record, 10);
0

精彩评论

暂无评论...
验证码 换一张
取 消