2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mqtt.espmilighthub.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * The {@link Helper} Removes the need for any external JSON libs
20 * @author Matthew Skinner - Initial contribution
25 * resolveJSON will return a value from any key/path that you give and the string can be terminated by any ,}"
29 public static String resolveJSON(String messageJSON, String jsonPath, int resultMaxLength) {
32 index = messageJSON.indexOf(jsonPath);
34 if ((index + jsonPath.length() + resultMaxLength) > messageJSON.length()) {
35 result = (messageJSON.substring(index + jsonPath.length(), messageJSON.length()));
37 result = (messageJSON.substring(index + jsonPath.length(),
38 index + jsonPath.length() + resultMaxLength));
40 index = result.indexOf(',');
42 index = result.indexOf('"');
44 index = result.indexOf('}');
48 return result.substring(0, index);
51 return result.substring(0, index);
54 result = result.substring(0, index);
55 index = result.indexOf('"');
59 return result.substring(0, index);