Android Question fix broken JSON string

ilan

Expert
Licensed User
Longtime User
hi

i am getting a json string from a library but sometimes there is a missing comma (,) at the end of the line and parsing is throwing an error.

looks like this:

B4X:
{
"metadata":{
    "key":"value",
    "key":"value",
    "key":"value",
    "key":"value",
"metadata2":{
    "key":"value",
    "key":"value",
    "key":"value",
    "key":"value"  <---- (missing comma)
    "key":"value"}
}
}

it is not always returning like this. there seems to be a bug in the main library so the question is how can i check if the json is a valid json and fix it if needed (add the missing commas)

i could do it using regex.split() and check if the last char is a "," and if not add it but is there a more nicer way?

thanx
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
You can do it in 1 line of code ( a long line I must add )
B4X:
' where j is the 'bad' or good JSON string
j= j.Replace(CRLF,"").Replace(TAB,"").Replace(" ","").Replace($""""$,$"",""$).Replace($"","$,$"",${CRLF}"$).Replace("{","{"&CRLF).Replace("}",CRLF&"}")
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

ilan

Expert
Licensed User
Longtime User
You can do it in 1 line of code ( a long line I must add )
B4X:
' where j is the 'bad' or good JSON string
j= j.Replace(CRLF,"").Replace(TAB,"").Replace(" ","").Replace($""""$,$"",""$).Replace($"","$,$"",${CRLF}"$).Replace("{","{"&CRLF).Replace("}",CRLF&"}")
yes using the replace function could do the job.
i was more thinking using Regex.Match

i could get the result using this patter on https://regex101.com/

B4X:
[\w+][^,\r\n][\s]?$

but for some reason on b4j i dont get any matches
 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
i remember this beeing a lib which is wrapped by someone for you, rigth?

What is the methodname which you are calling? and which output/return the JSON?
yes, actually i also managed to get it to work using JavaObject. i am putting an example and you can run it.
i am also including the jar file.

for some reason this line:

B4X:
    "ShaahZmanis26Degrees":"N/A"

is missing a comma at the end and parsing fails.
there is something in the library
 

Attachments

  • JO.zip
    81 KB · Views: 24
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i am putting an example and you can run it.
thank you.
The ComplexZmanimCalendar in the jar does not have a method called toJSON!

It seems that JavaObject is doing the conversation?
In this case it failed.

What about calling only existing methods in the newly generated ComplexZmanimCalendar?

like

B4X:
    Dim jo As JavaObject
    jo.InitializeNewInstance("com.kosherjava.zmanim.ComplexZmanimCalendar",Null)

    'getShaahZmanis19Point8Degrees
    Dim ShaahZmanis19Point8Degrees As Long =  jo.runMethod("getShaahZmanis19Point8Degrees", Null)
    Log($"ShaahZmanis19Point8Degrees -> ${ShaahZmanis19Point8Degrees}"$)
 
Upvote 0

emexes

Expert
Licensed User
is missing a comma at the end and parsing fails

and when that's fixed, it might still fall over complaining about mismatched braces (three opening, two closing):

B4X:
{
"metadata":{
    "key":"value",
    "key":"value",
    "key":"value",
    "key":"value",
"metadata2":{
    "key":"value",
    "key":"value",
    "key":"value",
    "key":"value"  <---- (missing comma)
    "key":"value"}
}
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
The ComplexZmanimCalendar in the jar does not have a method called toJSON!

It seems that JavaObject is doing the conversation?
the toJSON method is in AstronomicalCalendar.Class

ComplexZmanimCalendar extends ZmanimCalendar
ZmanimCalendar extends AstronomicalCalendar

so it is called from AstronomicalCalendar
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
and when that's fixed, it might still fall over complaining about mismatched braces (three opening, two closing):
there is a missing at the end "}"
i forgot to copy it but that's just an example it is not the real json string.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
actually it is inside ZmanimFormatter.class

B4X:
public static String toJSON(AstronomicalCalendar astronomicalCalendar) {
    ZmanimFormatter formatter = new ZmanimFormatter(5, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"), astronomicalCalendar.getGeoLocation().getTimeZone());
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    df.setTimeZone(astronomicalCalendar.getGeoLocation().getTimeZone());
    Date date = astronomicalCalendar.getCalendar().getTime();
    TimeZone tz = astronomicalCalendar.getGeoLocation().getTimeZone();
    boolean daylight = (tz.useDaylightTime() && tz.inDaylightTime(date));
    StringBuilder sb = new StringBuilder("{\n\"metadata\":{\n");
    sb.append("\t\"date\":\"").append(df.format(date)).append("\",\n");
    sb.append("\t\"type\":\"").append(astronomicalCalendar.getClass().getName()).append("\",\n");
    sb.append("\t\"algorithm\":\"").append(astronomicalCalendar.getAstronomicalCalculator().getCalculatorName()).append("\",\n");
    sb.append("\t\"location\":\"").append(astronomicalCalendar.getGeoLocation().getLocationName()).append("\",\n");
    sb.append("\t\"latitude\":\"").append(astronomicalCalendar.getGeoLocation().getLatitude()).append("\",\n");
    sb.append("\t\"longitude\":\"").append(astronomicalCalendar.getGeoLocation().getLongitude()).append("\",\n");
    sb.append("\t\"elevation\":\"").append(astronomicalCalendar.getGeoLocation().getElevation()).append("\",\n");
    sb.append("\t\"timeZoneName\":\"").append(tz.getDisplayName(daylight, 1)).append("\",\n");
    sb.append("\t\"timeZoneID\":\"").append(tz.getID()).append("\",\n");
    sb.append("\t\"timeZoneOffset\":\"")
      .append(tz.getOffset(astronomicalCalendar.getCalendar().getTimeInMillis()) / 3600000.0D)
      .append("\"");
    sb.append("},\n\"");
    if (astronomicalCalendar.getClass().getName().equals("com.kosherjava.zmanim.AstronomicalCalendar")) {
      sb.append("AstronomicalTimes");
    } else if (astronomicalCalendar.getClass().getName().equals("com.kosherjava.zmanim.ComplexZmanimCalendar")) {
      sb.append("Zmanim");
    } else if (astronomicalCalendar.getClass().getName().equals("com.kosherjava.zmanim.ZmanimCalendar")) {
      sb.append("BasicZmanim");
    }
    sb.append("\":{\n");
    Method[] theMethods = astronomicalCalendar.getClass().getMethods();
    String tagName = "";
    Object value = null;
    List<Zman> dateList = new ArrayList<>();
    List<Zman> durationList = new ArrayList<>();
    List<String> otherList = new ArrayList<>();
    for (int i = 0; i < theMethods.length; i++) {
      if (includeMethod(theMethods[i])) {
        tagName = theMethods[i].getName().substring(3);
        try {
          value = theMethods[i].invoke(astronomicalCalendar, (Object[])null);
          if (value == null) {
            otherList.add("\"" + tagName + "\":\"N/A\",");
          } else if (value instanceof Date) {
            dateList.add(new Zman((Date)value, tagName));
          } else if (value instanceof Long || value instanceof Integer) {
            if (((Long)value).longValue() == Long.MIN_VALUE) {
              otherList.add("\"" + tagName + "\":\"N/A\"");
            } else {
              durationList.add(new Zman((int)((Long)value).longValue(), tagName));
            }
          } else {
            otherList.add("\"" + tagName + "\":\"" + value + "\",");
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    Collections.sort(dateList, Zman.DATE_ORDER);
    int j;
    for (j = 0; j < dateList.size(); j++) {
      Zman zman = dateList.get(j);
      sb.append("\t\"").append(zman.getLabel()).append("\":\"");
      sb.append(formatter.formatDateTime(zman.getZman(), astronomicalCalendar.getCalendar()));
      sb.append("\",\n");
    }
    Collections.sort(durationList, Zman.DURATION_ORDER);
    for (j = 0; j < durationList.size(); j++) {
      Zman zman = durationList.get(j);
      sb.append("\t\"" + zman.getLabel()).append("\":\"");
      sb.append(formatter.format((int)zman.getDuration())).append("\",\n");
    }
    for (j = 0; j < otherList.size(); j++)
      sb.append("\t").append(otherList.get(j)).append("\n");
    sb.setLength(sb.length() - 2);
    sb.append("}\n}");
    return sb.toString();
  }
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
That'd be useful 🍻 real data to test solutions on, and one less thing to trip us up.

☝️
 
Upvote 0

emexes

Expert
Licensed User
☝️

There's no sample JSON record in that post or archive file.

I can see an instance in the Java code where it might be emitting a JSON tag:value element without a comma, but it'd be handy to have the missing-comma JSON output to confirm I'm looking at the right area.

If @DonManfred already has the library up and running and producing missing-comma JSON, then he will get to the finish line before I do.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
but it'd be handy to have the missing-comma JSON output to confirm I'm looking at the right area

B4X:
{
"metadata":{
    "date":"2024-05-01",
    "type":"com.kosherjava.zmanim.ComplexZmanimCalendar",
    "algorithm":"US National Oceanic and Atmospheric Administration Algorithm",
    "location":"Greenwich, England",
    "latitude":"51.4772",
    "longitude":"0.0",
    "elevation":"0.0",
    "timeZoneName":"Greenwich Mean Time",
    "timeZoneID":"GMT",
    "timeZoneOffset":"0.0"},
"Zmanim":{
    "Alos19Point8Degrees":"2024-05-01T01:38:05Z",
    "Alos19Degrees":"2024-05-01T01:49:15Z",
    "Alos18Degrees":"2024-05-01T02:01:59Z",
    "BeginAstronomicalTwilight":"2024-05-01T02:01:59Z",
    "Alos120Zmanis":"2024-05-01T02:02:25Z",
    "AlosBaalHatanya":"2024-05-01T02:14:50Z",
    "Alos16Point1Degrees":"2024-05-01T02:23:36Z",
    "AlosHashachar":"2024-05-01T02:23:36Z",
    "Alos120":"2024-05-01T02:31:12Z",
    "Alos96Zmanis":"2024-05-01T02:32:10Z",
    "Alos90Zmanis":"2024-05-01T02:39:37Z",
    "Alos96":"2024-05-01T02:55:12Z",
    "Alos90":"2024-05-01T03:01:12Z",
    "Alos72Zmanis":"2024-05-01T03:01:56Z",
    "BeginNauticalTwilight":"2024-05-01T03:03:26Z",
    "Misheyakir11Point5Degrees":"2024-05-01T03:07:52Z",
    "Misheyakir11Degrees":"2024-05-01T03:12:14Z",
    "Misheyakir10Point2Degrees":"2024-05-01T03:19:05Z",
    "Alos72":"2024-05-01T03:19:12Z",
    "Misheyakir9Point5Degrees":"2024-05-01T03:24:58Z",
    "Alos60":"2024-05-01T03:31:12Z",
    "Misheyakir7Point65Degrees":"2024-05-01T03:40:01Z",
    "BeginCivilTwilight":"2024-05-01T03:52:57Z",
    "Sunrise":"2024-05-01T04:31:12Z",
    "SeaLevelSunrise":"2024-05-01T04:31:12Z",
    "SofZmanShmaAlos16Point1ToSunset":"2024-05-01T06:38:41Z",
    "SofZmanShmaMGA19Point8Degrees":"2024-05-01T06:48:29Z",
    "SofZmanShmaAlos16Point1ToTzaisGeonim7Point083Degrees":"2024-05-01T06:50:26Z",
    "SofZmanShmaMGA18Degrees":"2024-05-01T07:00:14Z",
    "SofZmanShmaMGA18DegreesToFixedLocalChatzos":"2024-05-01T07:00:59Z",
    "SofZmanShmaMGA16Point1Degrees":"2024-05-01T07:10:55Z",
    "SofZmanShmaMGA16Point1DegreesToFixedLocalChatzos":"2024-05-01T07:11:48Z",
    "SofZmanShmaMGA120Minutes":"2024-05-01T07:14:24Z",
    "SofZmanShmaMGA96MinutesZmanis":"2024-05-01T07:14:53Z",
    "SofZmanShmaAteretTorah":"2024-05-01T07:17:26Z",
    "SofZmanShmaMGA90MinutesZmanis":"2024-05-01T07:18:36Z",
    "SofZmanShmaMGA96Minutes":"2024-05-01T07:26:24Z",
    "SofZmanShmaMGA90Minutes":"2024-05-01T07:29:24Z",
    "SofZmanShmaMGA72MinutesZmanis":"2024-05-01T07:29:45Z",
    "SofZmanShmaMGA90MinutesToFixedLocalChatzos":"2024-05-01T07:30:36Z",
    "SofZmanShmaMGA72Minutes":"2024-05-01T07:38:24Z",
    "SofZmanShmaMGA":"2024-05-01T07:38:24Z",
    "SofZmanShmaMGA72MinutesToFixedLocalChatzos":"2024-05-01T07:39:36Z",
    "SofZmanShmaBaalHatanya":"2024-05-01T08:11:43Z",
    "SofZmanShmaGRA":"2024-05-01T08:14:24Z",
    "SofZmanShmaGRASunriseToFixedLocalChatzos":"2024-05-01T08:15:36Z",
    "SofZmanShmaKolEliyahu":"2024-05-01T08:15:36Z",
    "SofZmanTfilaMGA19Point8Degrees":"2024-05-01T08:31:57Z",
    "SofZmanTfilaMGA18Degrees":"2024-05-01T08:39:39Z",
    "SofZmanTfilahAteretTorah":"2024-05-01T08:42:36Z",
    "SofZmanTfilaMGA16Point1Degrees":"2024-05-01T08:46:41Z",
    "SofZmanAchilasChametzMGA16Point1Degrees":"2024-05-01T08:46:41Z",
    "SofZmanTfilaMGA120Minutes":"2024-05-01T08:48:47Z",
    "SofZmanTfilaMGA96MinutesZmanis":"2024-05-01T08:49:07Z",
    "SofZmanTfilaMGA90MinutesZmanis":"2024-05-01T08:51:35Z",
    "SofZmanTfilaMGA96Minutes":"2024-05-01T08:56:47Z",
    "SofZmanShma3HoursBeforeChatzos":"2024-05-01T08:57:06Z",
    "SofZmanTfilaMGA90Minutes":"2024-05-01T08:58:47Z",
    "SofZmanTfilaMGA72MinutesZmanis":"2024-05-01T08:59:02Z",
    "SofZmanShmaFixedLocal":"2024-05-01T09:00:00Z",
    "SofZmanTfilaMGA72Minutes":"2024-05-01T09:04:47Z",
    "SofZmanAchilasChametzMGA72Minutes":"2024-05-01T09:04:47Z",
    "SofZmanTfilaMGA":"2024-05-01T09:04:47Z",
    "SofZmanTfilaBaalHatanya":"2024-05-01T09:27:00Z",
    "SofZmanAchilasChametzBaalHatanya":"2024-05-01T09:27:00Z",
    "SofZmanAchilasChametzGRA":"2024-05-01T09:28:47Z",
    "SofZmanTfilaGRA":"2024-05-01T09:28:47Z",
    "SofZmanTfilaGRASunriseToFixedLocalChatzos":"2024-05-01T09:30:24Z",
    "SofZmanTfila2HoursBeforeChatzos":"2024-05-01T09:57:06Z",
    "SofZmanTfilaFixedLocal":"2024-05-01T10:00:00Z",
    "SofZmanBiurChametzMGA16Point1Degrees":"2024-05-01T10:22:27Z",
    "SofZmanBiurChametzMGA72Minutes":"2024-05-01T10:31:11Z",
    "SofZmanBiurChametzBaalHatanya":"2024-05-01T10:42:18Z",
    "SofZmanBiurChametzGRA":"2024-05-01T10:43:11Z",
    "Chatzos":"2024-05-01T11:57:06Z",
    "SunTransit":"2024-05-01T11:57:06Z",
    "FixedLocalChatzos":"2024-05-01T12:00:00Z",
    "MinchaGedolaAteretTorah":"2024-05-01T12:15:32Z",
    "MinchaGedola30Minutes":"2024-05-01T12:27:06Z",
    "MinchaGedolaGRAFixedLocalChatzos30Minutes":"2024-05-01T12:30:00Z",
    "MinchaGedolaGreaterThan30":"2024-05-01T12:34:47Z",
    "MinchaGedola":"2024-05-01T12:34:47Z",
    "MinchaGedolaBaalHatanya":"2024-05-01T12:35:14Z",
    "MinchaGedolaBaalHatanyaGreaterThan30":"2024-05-01T12:35:14Z",
    "MinchaGedolaAhavatShalom":"2024-05-01T12:40:29Z",
    "MinchaGedola72Minutes":"2024-05-01T12:40:47Z",
    "MinchaGedola16Point1Degrees":"2024-05-01T12:46:07Z",
    "SamuchLeMinchaKetanaGRA":"2024-05-01T15:40:46Z",
    "MinchaKetanaAhavatShalom":"2024-05-01T16:08:35Z",
    "SamuchLeMinchaKetana72Minutes":"2024-05-01T16:16:46Z",
    "MinchaKetana":"2024-05-01T16:17:58Z",
    "MinchaKetanaGRAFixedLocalChatzosToSunset":"2024-05-01T16:18:58Z",
    "MinchaKetanaBaalHatanya":"2024-05-01T16:21:07Z",
    "MinchaKetanaAteretTorah":"2024-05-01T16:31:02Z",
    "SamuchLeMinchaKetana16Point1Degrees":"2024-05-01T16:45:33Z",
    "MinchaKetana72Minutes":"2024-05-01T16:59:58Z",
    "MinchaKetana16Point1Degrees":"2024-05-01T17:33:26Z",
    "PlagAlosToSunset":"2024-05-01T17:37:40Z",
    "PlagHamincha":"2024-05-01T17:50:57Z",
    "PlagHaminchaGRAFixedLocalChatzosToSunset":"2024-05-01T17:51:28Z",
    "PlagHaminchaBaalHatanya":"2024-05-01T17:55:14Z",
    "PlagAhavatShalom":"2024-05-01T17:57:08Z",
    "PlagHaminchaAteretTorah":"2024-05-01T18:17:30Z",
    "PlagAlos16Point1ToTzaisGeonim7Point083Degrees":"2024-05-01T18:19:46Z",
    "PlagHamincha60Minutes":"2024-05-01T18:38:27Z",
    "PlagHamincha72Minutes":"2024-05-01T18:47:57Z",
    "BainHashmashosYereim3Point05Degrees":"2024-05-01T18:56:40Z",
    "BainHasmashosYereim3Point05Degrees":"2024-05-01T18:56:40Z",
    "BainHashmashosYereim2Point8Degrees":"2024-05-01T18:58:23Z",
    "BainHasmashosYereim2Point8Degrees":"2024-05-01T18:58:23Z",
    "PlagHamincha72MinutesZmanis":"2024-05-01T19:01:38Z",
    "PlagHamincha90Minutes":"2024-05-01T19:02:12Z",
    "BainHasmashosYereim2Point1Degrees":"2024-05-01T19:03:14Z",
    "BainHashmashosYereim2Point1Degrees":"2024-05-01T19:03:14Z",
    "BainHashmashosYereim18Minutes":"2024-05-01T19:05:57Z",
    "BainHasmashosYereim18Minutes":"2024-05-01T19:05:57Z",
    "CandleLighting":"2024-05-01T19:05:57Z",
    "PlagHamincha96Minutes":"2024-05-01T19:06:57Z",
    "BainHashmashosYereim16Point875Minutes":"2024-05-01T19:07:05Z",
    "BainHasmashosYereim16Point875Minutes":"2024-05-01T19:07:05Z",
    "BainHasmashosYereim13Point5Minutes":"2024-05-01T19:10:27Z",
    "BainHashmashosYereim13Point5Minutes":"2024-05-01T19:10:27Z",
    "PlagHamincha90MinutesZmanis":"2024-05-01T19:19:18Z",
    "Sunset":"2024-05-01T19:23:57Z",
    "SeaLevelSunset":"2024-05-01T19:23:57Z",
    "PlagHamincha96MinutesZmanis":"2024-05-01T19:25:12Z",
    "PlagHamincha120Minutes":"2024-05-01T19:25:57Z",
    "PlagHamincha16Point1Degrees":"2024-05-01T19:33:08Z",
    "TzaisGeonim3Point65Degrees":"2024-05-01T19:44:33Z",
    "TzaisGeonim3Point676Degrees":"2024-05-01T19:44:45Z",
    "TzaisGeonim3Point7Degrees":"2024-05-01T19:44:56Z",
    "TzaisGeonim3Point8Degrees":"2024-05-01T19:45:41Z",
    "PlagHamincha120MinutesZmanis":"2024-05-01T19:48:45Z",
    "TzaisGeonim4Point37Degrees":"2024-05-01T19:49:58Z",
    "PlagHamincha18Degrees":"2024-05-01T19:50:42Z",
    "TzaisGeonim4Point61Degrees":"2024-05-01T19:51:47Z",
    "TzaisGeonim4Point8Degrees":"2024-05-01T19:53:13Z",
    "BainHashmashosRT13Point5MinutesBefore7Point083Degrees":"2024-05-01T19:57:27Z",
    "BainHasmashosRT13Point5MinutesBefore7Point083Degrees":"2024-05-01T19:57:27Z",
    "TzaisGeonim5Point88Degrees":"2024-05-01T20:01:30Z",
    "TzaisGeonim5Point95Degrees":"2024-05-01T20:02:03Z",
    "TzaisBaalHatanya":"2024-05-01T20:02:26Z",
    "EndCivilTwilight":"2024-05-01T20:02:26Z",
    "TzaisAteretTorah":"2024-05-01T20:03:57Z",
    "TzaisGeonim6Point45Degrees":"2024-05-01T20:05:57Z",
    "PlagHamincha19Point8Degrees":"2024-05-01T20:10:21Z",
    "TzaisGeonim7Point083Degrees":"2024-05-01T20:10:57Z",
    "BainHashmashosRT2Stars":"2024-05-01T20:12:02Z",
    "BainHasmashosRT2Stars":"2024-05-01T20:12:02Z",
    "Tzais50":"2024-05-01T20:13:57Z",
    "TzaisGeonim7Point67Degrees":"2024-05-01T20:15:38Z",
    "TzaisGeonim8Point5Degrees":"2024-05-01T20:22:22Z",
    "Tzais":"2024-05-01T20:22:22Z",
    "BainHashmashosRT58Point5Minutes":"2024-05-01T20:22:27Z",
    "BainHasmashosRT58Point5Minutes":"2024-05-01T20:22:27Z",
    "Tzais60":"2024-05-01T20:23:57Z",
    "TzaisGeonim9Point3Degrees":"2024-05-01T20:28:59Z",
    "TzaisGeonim9Point75Degrees":"2024-05-01T20:32:46Z",
    "Tzais72":"2024-05-01T20:35:57Z",
    "EndNauticalTwilight":"2024-05-01T20:52:25Z",
    "Tzais72Zmanis":"2024-05-01T20:53:14Z",
    "Tzais90":"2024-05-01T20:53:57Z",
    "Tzais96":"2024-05-01T20:59:57Z",
    "BainHasmashosRT13Point24Degrees":"2024-05-01T21:03:54Z",
    "BainHashmashosRT13Point24Degrees":"2024-05-01T21:03:54Z",
    "Tzais90Zmanis":"2024-05-01T21:15:33Z",
    "Tzais96Zmanis":"2024-05-01T21:22:59Z",
    "Tzais120":"2024-05-01T21:23:57Z",
    "Tzais16Point1Degrees":"2024-05-01T21:32:51Z",
    "Tzais120Zmanis":"2024-05-01T21:52:45Z",
    "Tzais18Degrees":"2024-05-01T21:54:58Z",
    "EndAstronomicalTwilight":"2024-05-01T21:54:58Z",
    "Tzais19Point8Degrees":"2024-05-01T22:19:41Z",
    "SolarMidnight":"2024-05-01T23:57:02Z",
    "ShaahZmanisGra":"PT1H14M23.735S",
    "TemporalHour":"PT1H14M23.735S",
    "ShaahZmanisBaalHatanya":"PT1H15M17.664S",
    "ShaahZmanis60Minutes":"PT1H24M23.735S",
    "ShaahZmanisAteretTorah":"PT1H25M10.108S",
    "ShaahZmanis72Minutes":"PT1H26M23.735S",
    "ShaahZmanisMGA":"PT1H26M23.735S",
    "ShaahZmanisAlos16Point1ToTzais3Point7":"PT1H26M46.638S",
    "ShaahZmanisAlos16Point1ToTzais3Point8":"PT1H26M50.375S",
    "ShaahZmanis72MinutesZmanis":"PT1H29M16.482S",
    "ShaahZmanis90Minutes":"PT1H29M23.735S",
    "ShaahZmanis96Minutes":"PT1H30M23.735S",
    "ShaahZmanis90MinutesZmanis":"PT1H32M59.668S",
    "ShaahZmanis96MinutesZmanis":"PT1H34M14.064S",
    "ShaahZmanis120Minutes":"PT1H34M23.735S",
    "ShaahZmanis16Point1Degrees":"PT1H35M46.270S",
    "ShaahZmanis120MinutesZmanis":"PT1H39M11.646S",
    "ShaahZmanis18Degrees":"PT1H39M24.929S",
    "ShaahZmanis19Point8Degrees":"PT1H43M27.998S",
    "Alos26Degrees":"N/A",
    "Tzais26Degrees":"N/A",
    "ZmanMolad":"N/A",
    "TchilasZmanKidushLevana7Days":"N/A",
    "SofZmanKidushLevana15Days":"N/A",
    "TchilasZmanKidushLevana3Days":"N/A",
    "ShaahZmanis26Degrees":"N/A"
    "PlagHamincha26Degrees":"N/A",
    "SofZmanKidushLevanaBetweenMoldos":"N/A"}
}

see line: ShaahZmanis26Degrees
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
ok i got an update.
so it turns out that the lib also has a "toString" method that exports the data to XML and there it seems to do the job well.
then i use XML2MAP and no error :)

B4X:
Sub Button1_Click
    Dim jo As JavaObject
    Dim xmlStr As String =  jo.InitializeNewInstance("com.kosherjava.zmanim.ComplexZmanimCalendar",Null).RunMethod("toString", Null)
    txtJson.Text = xmlStr
    Dim xml As Xml2Map
    xml.Initialize
    Log(xml.Parse(xmlStr))
End Sub

output:

B4X:
(MyMap) {Zmanim={Attributes={date=2024-05-01, type=com.kosherjava.zmanim.ComplexZmanimCalendar, algorithm=US National Oceanic and Atmospheric Administration Algorithm, location=Greenwich, England, latitude=51.4772, longitude=0.0, elevation=0.0, timeZoneName=Greenwich Mean Time, timeZoneID=GMT, timeZoneOffset=0.0}, Alos19Point8Degrees=2024-05-01T01:38:05Z, Alos19Degrees=2024-05-01T01:49:15Z, Alos18Degrees=2024-05-01T02:01:59Z, BeginAstronomicalTwilight=2024-05-01T02:01:59Z, Alos120Zmanis=2024-05-01T02:02:25Z, AlosBaalHatanya=2024-05-01T02:14:50Z, Alos16Point1Degrees=2024-05-01T02:23:36Z, AlosHashachar=2024-05-01T02:23:36Z, Alos120=2024-05-01T02:31:12Z, Alos96Zmanis=2024-05-01T02:32:10Z, Alos90Zmanis=2024-05-01T02:39:37Z, Alos96=2024-05-01T02:55:12Z, Alos90=2024-05-01T03:01:12Z, Alos72Zmanis=2024-05-01T03:01:56Z, BeginNauticalTwilight=2024-05-01T03:03:26Z, Misheyakir11Point5Degrees=2024-05-01T03:07:52Z, Misheyakir11Degrees=2024-05-01T03:12:14Z, Misheyakir10Point2Degrees=2024-05-01T03:19:05Z, Alos72=2024-05-01T03:19:12Z, Misheyakir9Point5Degrees=2024-05-01T03:24:58Z, Alos60=2024-05-01T03:31:12Z, Misheyakir7Point65Degrees=2024-05-01T03:40:01Z, BeginCivilTwilight=2024-05-01T03:52:57Z, SeaLevelSunrise=2024-05-01T04:31:12Z, Sunrise=2024-05-01T04:31:12Z, SofZmanShmaAlos16Point1ToSunset=2024-05-01T06:38:41Z, SofZmanShmaMGA19Point8Degrees=2024-05-01T06:48:29Z, SofZmanShmaAlos16Point1ToTzaisGeonim7Point083Degrees=2024-05-01T06:50:26Z, SofZmanShmaMGA18Degrees=2024-05-01T07:00:14Z, SofZmanShmaMGA18DegreesToFixedLocalChatzos=2024-05-01T07:00:59Z, SofZmanShmaMGA16Point1Degrees=2024-05-01T07:10:55Z, SofZmanShmaMGA16Point1DegreesToFixedLocalChatzos=2024-05-01T07:11:48Z, SofZmanShmaMGA120Minutes=2024-05-01T07:14:24Z, SofZmanShmaMGA96MinutesZmanis=2024-05-01T07:14:53Z, SofZmanShmaAteretTorah=2024-05-01T07:17:26Z, SofZmanShmaMGA90MinutesZmanis=2024-05-01T07:18:36Z, SofZmanShmaMGA96Minutes=2024-05-01T07:26:24Z, SofZmanShmaMGA90Minutes=2024-05-01T07:29:24Z, SofZmanShmaMGA72MinutesZmanis=2024-05-01T07:29:45Z, SofZmanShmaMGA90MinutesToFixedLocalChatzos=2024-05-01T07:30:36Z, SofZmanShmaMGA72Minutes=2024-05-01T07:38:24Z, SofZmanShmaMGA=2024-05-01T07:38:24Z, SofZmanShmaMGA72MinutesToFixedLocalChatzos=2024-05-01T07:39:36Z, SofZmanShmaBaalHatanya=2024-05-01T08:11:43Z, SofZmanShmaGRA=2024-05-01T08:14:24Z, SofZmanShmaGRASunriseToFixedLocalChatzos=2024-05-01T08:15:36Z, SofZmanShmaKolEliyahu=2024-05-01T08:15:36Z, SofZmanTfilaMGA19Point8Degrees=2024-05-01T08:31:57Z, SofZmanTfilaMGA18Degrees=2024-05-01T08:39:39Z, SofZmanTfilahAteretTorah=2024-05-01T08:42:36Z, SofZmanAchilasChametzMGA16Point1Degrees=2024-05-01T08:46:41Z, SofZmanTfilaMGA16Point1Degrees=2024-05-01T08:46:41Z, SofZmanTfilaMGA120Minutes=2024-05-01T08:48:47Z, SofZmanTfilaMGA96MinutesZmanis=2024-05-01T08:49:07Z, SofZmanTfilaMGA90MinutesZmanis=2024-05-01T08:51:35Z, SofZmanTfilaMGA96Minutes=2024-05-01T08:56:47Z, SofZmanShma3HoursBeforeChatzos=2024-05-01T08:57:06Z, SofZmanTfilaMGA90Minutes=2024-05-01T08:58:47Z, SofZmanTfilaMGA72MinutesZmanis=2024-05-01T08:59:02Z, SofZmanShmaFixedLocal=2024-05-01T09:00:00Z, SofZmanAchilasChametzMGA72Minutes=2024-05-01T09:04:47Z, SofZmanTfilaMGA72Minutes=2024-05-01T09:04:47Z, SofZmanTfilaMGA=2024-05-01T09:04:47Z, SofZmanAchilasChametzBaalHatanya=2024-05-01T09:27:00Z, SofZmanTfilaBaalHatanya=2024-05-01T09:27:00Z, SofZmanAchilasChametzGRA=2024-05-01T09:28:47Z, SofZmanTfilaGRA=2024-05-01T09:28:47Z, SofZmanTfilaGRASunriseToFixedLocalChatzos=2024-05-01T09:30:24Z, SofZmanTfila2HoursBeforeChatzos=2024-05-01T09:57:06Z, SofZmanTfilaFixedLocal=2024-05-01T10:00:00Z, SofZmanBiurChametzMGA16Point1Degrees=2024-05-01T10:22:27Z, SofZmanBiurChametzMGA72Minutes=2024-05-01T10:31:11Z, SofZmanBiurChametzBaalHatanya=2024-05-01T10:42:18Z, SofZmanBiurChametzGRA=2024-05-01T10:43:11Z, Chatzos=2024-05-01T11:57:06Z, SunTransit=2024-05-01T11:57:06Z, FixedLocalChatzos=2024-05-01T12:00:00Z, MinchaGedolaAteretTorah=2024-05-01T12:15:32Z, MinchaGedola30Minutes=2024-05-01T12:27:06Z, MinchaGedolaGRAFixedLocalChatzos30Minutes=2024-05-01T12:30:00Z, MinchaGedolaGreaterThan30=2024-05-01T12:34:47Z, MinchaGedola=2024-05-01T12:34:47Z, MinchaGedolaBaalHatanyaGreaterThan30=2024-05-01T12:35:14Z, MinchaGedolaBaalHatanya=2024-05-01T12:35:14Z, MinchaGedolaAhavatShalom=2024-05-01T12:40:29Z, MinchaGedola72Minutes=2024-05-01T12:40:47Z, MinchaGedola16Point1Degrees=2024-05-01T12:46:07Z, SamuchLeMinchaKetanaGRA=2024-05-01T15:40:46Z, MinchaKetanaAhavatShalom=2024-05-01T16:08:35Z, SamuchLeMinchaKetana72Minutes=2024-05-01T16:16:46Z, MinchaKetana=2024-05-01T16:17:58Z, MinchaKetanaGRAFixedLocalChatzosToSunset=2024-05-01T16:18:58Z, MinchaKetanaBaalHatanya=2024-05-01T16:21:07Z, MinchaKetanaAteretTorah=2024-05-01T16:31:02Z, SamuchLeMinchaKetana16Point1Degrees=2024-05-01T16:45:33Z, MinchaKetana72Minutes=2024-05-01T16:59:58Z, MinchaKetana16Point1Degrees=2024-05-01T17:33:26Z, PlagAlosToSunset=2024-05-01T17:37:40Z, PlagHamincha=2024-05-01T17:50:57Z, PlagHaminchaGRAFixedLocalChatzosToSunset=2024-05-01T17:51:28Z, PlagHaminchaBaalHatanya=2024-05-01T17:55:14Z, PlagAhavatShalom=2024-05-01T17:57:08Z, PlagHaminchaAteretTorah=2024-05-01T18:17:30Z, PlagAlos16Point1ToTzaisGeonim7Point083Degrees=2024-05-01T18:19:46Z, PlagHamincha60Minutes=2024-05-01T18:38:27Z, PlagHamincha72Minutes=2024-05-01T18:47:57Z, BainHashmashosYereim3Point05Degrees=2024-05-01T18:56:40Z, BainHasmashosYereim3Point05Degrees=2024-05-01T18:56:40Z, BainHashmashosYereim2Point8Degrees=2024-05-01T18:58:23Z, BainHasmashosYereim2Point8Degrees=2024-05-01T18:58:23Z, PlagHamincha72MinutesZmanis=2024-05-01T19:01:38Z, PlagHamincha90Minutes=2024-05-01T19:02:12Z, BainHashmashosYereim2Point1Degrees=2024-05-01T19:03:14Z, BainHasmashosYereim2Point1Degrees=2024-05-01T19:03:14Z, BainHasmashosYereim18Minutes=2024-05-01T19:05:57Z, BainHashmashosYereim18Minutes=2024-05-01T19:05:57Z, CandleLighting=2024-05-01T19:05:57Z, PlagHamincha96Minutes=2024-05-01T19:06:57Z, BainHashmashosYereim16Point875Minutes=2024-05-01T19:07:05Z, BainHasmashosYereim16Point875Minutes=2024-05-01T19:07:05Z, BainHashmashosYereim13Point5Minutes=2024-05-01T19:10:27Z, BainHasmashosYereim13Point5Minutes=2024-05-01T19:10:27Z, PlagHamincha90MinutesZmanis=2024-05-01T19:19:18Z, SeaLevelSunset=2024-05-01T19:23:57Z, Sunset=2024-05-01T19:23:57Z, PlagHamincha96MinutesZmanis=2024-05-01T19:25:12Z, PlagHamincha120Minutes=2024-05-01T19:25:57Z, PlagHamincha16Point1Degrees=2024-05-01T19:33:08Z, TzaisGeonim3Point65Degrees=2024-05-01T19:44:33Z, TzaisGeonim3Point676Degrees=2024-05-01T19:44:45Z, TzaisGeonim3Point7Degrees=2024-05-01T19:44:56Z, TzaisGeonim3Point8Degrees=2024-05-01T19:45:41Z, PlagHamincha120MinutesZmanis=2024-05-01T19:48:45Z, TzaisGeonim4Point37Degrees=2024-05-01T19:49:58Z, PlagHamincha18Degrees=2024-05-01T19:50:42Z, TzaisGeonim4Point61Degrees=2024-05-01T19:51:47Z, TzaisGeonim4Point8Degrees=2024-05-01T19:53:13Z, BainHasmashosRT13Point5MinutesBefore7Point083Degrees=2024-05-01T19:57:27Z, BainHashmashosRT13Point5MinutesBefore7Point083Degrees=2024-05-01T19:57:27Z, TzaisGeonim5Point88Degrees=2024-05-01T20:01:30Z, TzaisGeonim5Point95Degrees=2024-05-01T20:02:03Z, TzaisBaalHatanya=2024-05-01T20:02:26Z, EndCivilTwilight=2024-05-01T20:02:26Z, TzaisAteretTorah=2024-05-01T20:03:57Z, TzaisGeonim6Point45Degrees=2024-05-01T20:05:57Z, PlagHamincha19Point8Degrees=2024-05-01T20:10:21Z, TzaisGeonim7Point083Degrees=2024-05-01T20:10:57Z, BainHasmashosRT2Stars=2024-05-01T20:12:02Z, BainHashmashosRT2Stars=2024-05-01T20:12:02Z, Tzais50=2024-05-01T20:13:57Z, TzaisGeonim7Point67Degrees=2024-05-01T20:15:38Z, TzaisGeonim8Point5Degrees=2024-05-01T20:22:22Z, Tzais=2024-05-01T20:22:22Z, BainHasmashosRT58Point5Minutes=2024-05-01T20:22:27Z, BainHashmashosRT58Point5Minutes=2024-05-01T20:22:27Z, Tzais60=2024-05-01T20:23:57Z, TzaisGeonim9Point3Degrees=2024-05-01T20:28:59Z, TzaisGeonim9Point75Degrees=2024-05-01T20:32:46Z, Tzais72=2024-05-01T20:35:57Z, EndNauticalTwilight=2024-05-01T20:52:25Z, Tzais72Zmanis=2024-05-01T20:53:14Z, Tzais90=2024-05-01T20:53:57Z, Tzais96=2024-05-01T20:59:57Z, BainHashmashosRT13Point24Degrees=2024-05-01T21:03:54Z, BainHasmashosRT13Point24Degrees=2024-05-01T21:03:54Z, Tzais90Zmanis=2024-05-01T21:15:33Z, Tzais96Zmanis=2024-05-01T21:22:59Z, Tzais120=2024-05-01T21:23:57Z, Tzais16Point1Degrees=2024-05-01T21:32:51Z, Tzais120Zmanis=2024-05-01T21:52:45Z, Tzais18Degrees=2024-05-01T21:54:58Z, EndAstronomicalTwilight=2024-05-01T21:54:58Z, Tzais19Point8Degrees=2024-05-01T22:19:41Z, SolarMidnight=2024-05-01T23:57:02Z, ShaahZmanisGra=PT1H14M23.735S, TemporalHour=PT1H14M23.735S, ShaahZmanisBaalHatanya=PT1H15M17.664S, ShaahZmanis60Minutes=PT1H24M23.735S, ShaahZmanisAteretTorah=PT1H25M10.108S, ShaahZmanis72Minutes=PT1H26M23.735S, ShaahZmanisMGA=PT1H26M23.735S, ShaahZmanisAlos16Point1ToTzais3Point7=PT1H26M46.638S, ShaahZmanisAlos16Point1ToTzais3Point8=PT1H26M50.375S, ShaahZmanis72MinutesZmanis=PT1H29M16.482S, ShaahZmanis90Minutes=PT1H29M23.735S, ShaahZmanis96Minutes=PT1H30M23.735S, ShaahZmanis90MinutesZmanis=PT1H32M59.668S, ShaahZmanis96MinutesZmanis=PT1H34M14.064S, ShaahZmanis120Minutes=PT1H34M23.735S, ShaahZmanis16Point1Degrees=PT1H35M46.270S, ShaahZmanis120MinutesZmanis=PT1H39M11.646S, ShaahZmanis18Degrees=PT1H39M24.929S, ShaahZmanis19Point8Degrees=PT1H43M27.998S, ZmanMolad=N/A, Tzais26Degrees=N/A, Alos26Degrees=N/A, SofZmanKidushLevanaBetweenMoldos=N/A, PlagHamincha26Degrees=N/A, TchilasZmanKidushLevana3Days=N/A, SofZmanKidushLevana15Days=N/A, TchilasZmanKidushLevana7Days=N/A, ShaahZmanis26Degrees=N/A}}

thanks again @DonManfred , @emexes and @Daestrum 🙏 🙏 🙏
 
Upvote 0

emexes

Expert
Licensed User
see line: ShaahZmanis26Degrees

There are two Java lines that output "N/A" elements. One has a trailing comma, the other doesn't.

I am guessing that Zman() returns an tag:value string with a trailing comma, which would mean that all the dateList.add() operations add strings with a trailing comma, except for line 12.

Java:
for (int i = 0; i < theMethods.length; i++) {
    if (includeMethod(theMethods[i])) {
        tagName = theMethods[i].getName().substring(3);
        try {
            value = theMethods[i].invoke(astronomicalCalendar, (Object[])null);
            if (value == null) {
                otherList.add("\"" + tagName + "\":\"N/A\",");
            } else if (value instanceof Date) {
                dateList.add(new Zman((Date)value, tagName));
            } else if (value instanceof Long || value instanceof Integer) {
                if (((Long)value).longValue() == Long.MIN_VALUE) {
                    otherList.add("\"" + tagName + "\":\"N/A\"");
                } else {
                    durationList.add(new Zman((int)((Long)value).longValue(), tagName));
                }
            } else {
                otherList.add("\"" + tagName + "\":\"" + value + "\",");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Upvote 0

emexes

Expert
Licensed User
One has a trailing comma, the other doesn't.

I have a vague recollection of an issue with space shuttle code error that involved either a missing comma, or a comma that should have been a full-stop, or vice-versa.

edit: might have been Mariner, not space shuttle, where apparently a dot had replaced the comma

I also have a strong recollection of once spending an hour on the phone tracking down a Turbo Pascal compilation error that turned out to be it was missing the end-of-program full stop or semicolon.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I have a vague recollection of an issue with space shuttle code error that involved either a missing comma, or a comma that should have been a full-stop, or vice-versa.
"There is a useful lesson to be learned from the failure of one of the earliest planetary probes launched by NASA. The cause of the failure was eventually traced to a statement in its control software similar to this:
DO 15 I = 1.100
when what should have been written was:
DO 15 I = 1,100
but somehow a dot had replaced the comma. Because Fortran ignores spaces, this was seen by the compiler as:
DO15I = 1.100
which is a perfectly valid assignment to a variable called DO15I and not at all what was intended."

 
Upvote 0
Top