如何从数组中获取每个项目?

时间:2019-09-24 07:33:08

标签: kotlin

我有:

sizes = ["UK7","UK8","UK9","UK10"]

我尝试过:

val listSizes= sizes?.split(",").toTypedArray()

listSizes仅为[]。为什么?

1 个答案:

答案 0 :(得分:1)

您可以尝试-

export async function getStoreDistance(locationDetails) {
  console.log('stordistance', locationDetails);
  let destinationRequest = locationDetails.destinations.map(location => {
    return `${location.lat},${location.long}`;
  });
  return await axios
    .get(
      `https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial
      &origins=${locationDetails.origins.map(function(locationDetail) {
        return locationDetail;
      })}
      &destinations=${destinationRequest}&key=************j****c`,
    )
    .then(function(response) {
      // handle success
      return response;
    })
    .catch(function(error) {
      // handle error
      return error;
    });
}

val sizes = listOf("UK7","UK8","UK9","UK10"); val listSizes= sizes.toTypedArray(); println(listSizes.contentToString()); //[UK7, UK8, UK9, UK10] 已经是一个字符串列表。仅当您尝试破坏包含 逗号的字符串(例如sizes)时,才需要用逗号split

或者,您也可以使用"UK7, UK8, UK9"-

arrayOf()