如何从 JSON 数据中获取 1c 中的列表记录

How to get a list records in 1c from JSON data

我从下面写的地址得到1C中的JSON数据。只有一个注册时没有问题。但是我不能列出很多记录。它给出错误“找不到对象字段(密钥)”。我需要做什么才能列出记录?请帮忙。

              Host     = "jsonplaceholder.typicode.com/";
          HTTPRequest = New HTTPRequest;
              // HTTPRequest.ResourceAddress = "todos/1";
               HTTPRequest.ResourceAddress = "photos/" ;// ThisObject.Attribute2;
               HTTPConnection         = New HTTPConnection(host,,,,,10,New OpenSSLSecureConnection);
               HTTPAnswer               = HTTPConnection.Get(HTTPRequest);
               stringAnswer= HTTPAnswer.GetBodyAsString();
               JSONReader = New JSONReader;
               JSONReader.SetString(stringAnswer);
               JsonResult = ReadJson(JSONReader,True);      

                For each strResult in JsonResult Do
                    If (strResult.Key = "url") Then
                        Message(strResult.Value);                                                  
                     EndIf;
               EndDo;

你的代码应该是这样的:

Host = "jsonplaceholder.typicode.com/";

HTTPRequest = New HTTPRequest;

HTTPRequest.ResourceAddress = "photos/" ;

HTTPConnection = New HTTPConnection(host,,,,,10,New OpenSSLSecureConnection);

HTTPAnswer = HTTPConnection.Get(HTTPRequest);

stringAnswer = HTTPAnswer.GetBodyAsString();

JSONReader = New JSONReader;

JSONReader.SetString(stringAnswer);

JsonResult = ReadJson(JSONReader,True);

  For each strResult in JsonResult Do

  For Each curElement In strResult Do 

     If (curElement.Key = "url") Then

        Message(curElement.Value);

        Break; // since the value curElement.Key = "url" can be only once, we can exit the loop

     EndIf;

  EndDo;

EndDo;

JsonResult 是一个值数组(请参阅 scr.1)。数组的每个元素都是一个映射 strResult (scr.2)。首先,在循环中,我们遍历数组的所有元素,在嵌套循环中,我们遍历匹配的字段。